简体   繁体   中英

Problem with using checkbox inside listview

I am trying to use check box inside a listview. But i'm unable to select the list item if i keep check box inside the listview. If i use checkbox, i cant select List item. How to overcome this problem? Any help is highly appreciated and thanks in advance.

In list view there is a property called focusable set it true and also try setting Draw selector to true. With this you should be able to focus or select the list item.

Now for check box, have setOnCheckedChangeListener (CompoundButton.OnCheckedChangeListener listener) implemented to handle the check box change state.

I think this should work.raj's answer is also correct.

ArrayList<String>  displayName = new ArrayList();

displayName.add("A");
displayName.add("B");
displayName.add("C");

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, displayName));
listView= getListView();
listView.setItemsCanFocus(false);
listView.setTextFilterEnabled(true);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

can u share your code what u have written????? check the code given below

ArrayList<String> lv_items = new ArrayList();
lv_items.add("Birth Date");
lv_items.add("Anniversary Date");
lv_items.add("Joining Date");
lv_items.add("Meeting Date");
lv_items.add("Appraisal Date");
ArrayAdapter aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, lv_items);
ListView lView = (ListView) findViewById(R.id.ListView01);
// Set option as Multiple Choice. So that user can able to select more the one option from list
lView.setAdapter(aa);
lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM