I have implemented DialogFragment
in my app where I show a list of Countries/States to the user for selection. The list is displayed properly by using the below code. But I just realized when I scroll down the checked boxes and they are not visible on the screen they don't retain check mark when I scroll up again to them. I was thinking I could use an ArrayList
to hold the checked items and then use that to check/uncheck the boxes. But I may be there is some other and better way to do it in setMultiChoiceItems
. Also, how would I reconcile ArrayList
with setMultiChoiceItems
parameter isCheckedColumn
that is "Show_Ad" in my case.
I don't update the Database
until the user presses OK button. So on scroll the Dialog is reusing the old cursor
and setting checkboxes according to that. That is what I think is happening.
Can anyone please tell me how I should go about retaining the state of the checkboxes
?
Thank you.
NextDialogIs = "Region";
regionsCur = database.rawQuery("SELECT distinct max(Show_Ad) as Show_Ad, State_ID as _id, State_Name, State_ID FROM State_Regions group by State_Name ORDER BY State_Name ASC ", null);
// add a checkbox list
builder.setMultiChoiceItems(regionsCur, "Show_Ad", "State_Name",new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked){
// user checked or unchecked a box
regionsCur.moveToPosition(which);
if(isChecked) {
regionID.add(regionsCur.getInt(1));
}
}
});
Aucun commentaire:
Enregistrer un commentaire