Android: simple_list_item_single_choice not working with ArrayAdapter

In my ListView, I need the only choice to delete the item. For this, I use simple_list_item_single_choice with an ArrayAdapter. It shows me the only choice in my ListView. But I can not click on this check box.

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);
+4
source share
1 answer

You need to use ListView.setChoiceMode (int mode) . how

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 look 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);
+6
source

All Articles