1

I have added a checkbox inside a list view, but i am able to select and unselect only the checkboxes but i cannot select the list item. How to overcome this problem? Any help is appreciated and thanks in advance...

My Code Goes Here

List<String> lst = dh.selectAll();
    lv = (ListView)findViewById(R.id.listView1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list,R.id.textViewx,lst);
    lv.setAdapter(adapter);


    lv.setOnItemClickListener(this);

dh.selectall() -> Contains the listarray of items from database; lv -> list view identified I've used array adapter and identified a textview to enter items in listview at last, I've given a clicklistener to the listview by implementing OnItemClickListener.

2
  • You can find more detail and example about [here][1]. [1]: stackoverflow.com/questions/5417339/… Commented Sep 12, 2011 at 12:49
  • 1
    Including the problematic code in your question will most likely yield better answers. Commented Sep 12, 2011 at 12:58

2 Answers 2

1

with out these two lines the list will display the check box but would not be able to check/unchek

ListView listView = getListView();
mainListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Sign up to request clarification or add additional context in comments.

1 Comment

I can only select and de-select the checkboxes. But i cannot select a list item....
0

You should use multiple choice listview. Fits your needs perfectly. Here is a link to a good tutorial : http://mubasheralam.com/tutorials/android/how-create-multiple-choice-list

Update 1

listViewObj.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

When you have a checkable item in your listview, the touch on item will not be delivered to item. Just to test, set your checkbox as non clickable. chkox.setClickable(false); and test. The clicks will be delivered to your item.

Update 2

You should use android.R.layout.simple_list_item_multiple_choice for list item.

List<String> lst = dh.selectAll();
lv = (ListView)findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                         android.R.layout.simple_list_item_multiple_choice, lst);

lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setListAdapter(adapter);

3 Comments

Thats fine. Just use listview object directly instead of calling getListView
Add your current code to the question. Which layout id are you passing to your adapter?
You should set android:focusable="false" in the XML layout for your checkbox in the list item. Otherwise the checkbox will steal all click events and your list view will not get them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.