I have a multichoice alert dialog which displays an arraylist properly in a list with checkbox in each row.I want to change the value of the checked item in the list ie...if it is checked it should be 1 else 0.The problem is on clicking it only fetches the last item in the list and changes its value
alertdialogbuilder = new AlertDialog.Builder(FormBuilderActivity.this);
final boolean[] Selectedtruefalse = new boolean[multiSelectPopulationList[0].size()];
for(int x=0;x<multiSelectPopulationList[0].size();x++)
{
if(multiSelectPopulationList[0].get(x).getValue()==0)
{
Selectedtruefalse[x]=false;
}
else
{
Selectedtruefalse[x]=true;
}
}
final ArrayList<MultiSelectModel> ItemsIntoList;
ItemsIntoList = new ArrayList<>();
ItemsIntoList.clear();
ItemsIntoList.addAll(multiSelectPopulationList[0]);
final String[] AlertDialogItems = new String[multiSelectPopulationList[0].size()];
for(int z=0;z<multiSelectPopulationList[0].size();z++)
{
AlertDialogItems[z]=multiSelectPopulationList[0].get(z).getPopulationListItem();
}
alertdialogbuilder.setMultiChoiceItems(AlertDialogItems, Selectedtruefalse, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(multiSelectPopulationList[0].get(which).getValue()==0)
{
multiSelectModel.setValue(1);
multiSelectPopulationList[0].set(which, multiSelectModel);
Log.d("Multisel["+which+"]rowlabel",multiSelectPopulationList[0].get(which).getName());
Log.d("Multisel["+which+"]rowId",multiSelectPopulationList[0].get(which).getRowId());
Log.d("Multisel["+which+"]optionValue",multiSelectPopulationList[0].get(which).getPopulationListItem());
Log.d("Multisel["+which+"]checkValue",String.valueOf(multiSelectPopulationList[0].get(which).getValue()));
}
else
{
multiSelectModel.setValue(1);
multiSelectPopulationList[0].set(which, multiSelectModel);
Log.d("Multisel["+which+"]rowlabel",multiSelectPopulationList[0].get(which).getName());
Log.d("Multisel["+which+"]rowId",multiSelectPopulationList[0].get(which).getRowId());
Log.d("Multisel["+which+"]optionValue",multiSelectPopulationList[0].get(which).getPopulationListItem());
Log.d("Multisel["+which+"]checkValue",String.valueOf(multiSelectPopulationList[0].get(which).getValue()));
}
}
});
I have tried custom multiselect pop up dialog with search option.
Create class name with MultiSelect.java
create xml file with name pop_up_list.xml
create Adapter Class with name PrefStateAdapter.java
finally method that will show multiselect pop up
This is working code, you need to change in drawable in xml file I hope this will help you Happy coding!!!! All the best!!