6

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);
Developer
  • 1,435
  • 2
  • 23
  • 48

1 Answers1

13

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);
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186