I have a RecyclerView
which contains several data stored on CardView
after long press i am enabling a context menu, i am getting the position of particular card and i am able to display the data on Toast also.
But what i want to do is to Store the data in List<> and then retrieve it from another activity class where i can use those data to set on some particular EditText
.
I am not sure where i am getting wrong here is my code:-
getting Data on long press and storing in List
public List<String> Data=new ArrayList<>();
TextView name,qunat,refill;
String nameMed,quantity,refillAmt;
@Override
public void onItemLongClick(View view, int position) {
name = (TextView) view.findViewById(R.id.nameOfUpmingMed);
qunat=(TextView)view.findViewById(R.id.QuantOfMed);
refill=(TextView)view.findViewById(R.id.ReffilAmt);
nameMed = name.getText().toString();
quantity=qunat.getText().toString();
refillAmt=refill.getText().toString();
passData(nameMed,quantity,refillAmt,);
// Data.add(nameMed);Data.add(quantity);Data.add(refillAmt);
}
}));
public List<String> passData(String name, String quant, String refillAmt){
String Name,Quant,Refill;
Name=name;Quant=quant;Refill=refillAmt;
Data.add(Name);
Data.add(Quant);
Data.add(Refill);
for(int i=0;i<Data.size();i++){
Toast.makeText(getActivity(), "Pressed card is and "+Data.get(i), Toast.LENGTH_SHORT).show();
}
return Data;
}
When I am retrieving data on long click it is working fine, it give the data of particular card pressed. But when I am passing the Data to list on long press it shows the previous pressed data first and then the current data.
My 2nd question is i am trying to access this list in another class but it is not working.
code for other class is
prescriptionFragment=new PrescriptionFragment();
for(int i=0;i < prescriptionFragment.Data.size();i++){
if(i==0){
Toast.makeText(getApplication(),"data is "+prescriptionFragment.Data.get(i),Toast.LENGTH_LONG).show();
}
}
How to do this, how can i get data from one class to another on long press of a card view. Or is there any other way of doing this.