In my ListView i want single selection to delete the item. For that i am using simple_list_item_single_choice with ArrayAdapter. It show me the single choice option in my ListView. But i am not able to click on that checkbox.
Here is my code:
ArrayList array_list_title = mydb.getTitle();
System.out.println(array_list_title);
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, array_list_title);
listView.setAdapter(arrayAdapter);
You need to use ListView.setChoiceMode(int mode). Like
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Enables multiple selection
or
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Enables single selection
to enable checkboxes.
So your code will be like
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, array_list_title);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setAdapter(arrayAdapter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With