Hello everyone I've been struggling for 3 days to find a solution to this does anyone can point me to the right direction? My problem is as follows:
What I have: 1. A listView populated through Objects of type "Sales" 2. A single row is constructed with a checkbox and 2 strings with name and email. 3. I'm extending from BaseAdapter
What I need: - When the user push a button called "next"(leads to a new activity) all the checked objects must remain selected an only those should be visible in the next activity.
Im not talking about passing primitive datatypes instead I'm talking about passing and maintaining a reference to all selected (checked) Objects in a list in another activity
What I have tried -I have created a static ArrayList and tryied to save all the selected objects in the Listener of the checkbox when the user checks a box I add this object to my static array but is not working it gives a NULL array when I try to read it back from another activity.
- I tried to save it through SharedPreferences but it only saves the last index of the array.
My short and generic question would be: ¿Where do I look to save a selected object from a checkbox listener or how can I maintain only the ones selected in another activity?
this is my checkBoxListener not sure how can I save the selected object
chkBoxUser.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if (chkBoxUser.isChecked())
{
//saveData(obj, obj.saleId);
ArrayList<SaleModel> saleSelected = new ArrayList<>();
saleSelected.add(obj);
Toast.makeText(context, "Object added!: " + saleSelected.get(0), Toast.LENGTH_SHORT).show();
}
else
{
saleSelected.remove(obj);
Toast.makeText(context, "UNChecked: " + obj.customerFirstName, Toast.LENGTH_SHORT).show();
}
}
});