Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: simple_list_item_single_choice is not working with ArrayAdapter

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);
like image 221
Developer Avatar asked Sep 04 '14 06:09

Developer


1 Answers

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);
like image 183
Pankaj Kumar Avatar answered Sep 30 '22 17:09

Pankaj Kumar