In my activity I have 4 items in a list view with checkboxes in each row. After I leave activity I want all the checked item position numbers in an arraylist. This code works fine when user clicks all the checkboxes ones and leave the activity. But when user clicks a checkbox and then unchecks it, item position is arraylist doesnt able to clear. This methood is in my CustomAdapter class.
class GameAdapter extends BaseAdapter{
private ArrayList<Integer> positions = new ArrayList<Integer>();
public ArrayList<Integer> getPositions() {
return positions;
}
getView(....){
final ViewHolder holder;
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(holder.checkBox.isChecked()) {
positions.add(position);
}
}
});
}
}
I am handling this adapter class in the activity where my listview resides. There I am taking this arraylist values like this
ArrayList<Integer> gamePositions = mGameAdapter.getPositions();
String itemNumbers = gamePositions.toString();
in itemNumber string I want all the checked item number values.
Thank you in advance for guidance....
Aucun commentaire:
Enregistrer un commentaire