2

I'm trying to add a CheckBox to every item in my ListView. I can't put a CheckBox widget in the ListView, so how do I do it? I think the Android settings has something like this.

2 Answers 2

5

Off the top of my head, you should create an xml layout file representing an item in the ListView, in which you would declare a CheckBox. You can then set the adapter to use your layout for every item as follows:

ArrayAdapter<T> adapter = new ArrayAdapter<T>(this, R.layout.list_item, listReference); 
setListAdapter(adapter);

setListAdapter is a method in ListActivity. Your list_item.xml should have the CheckBox defined in it.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to extend a view adapter class and provide your own logic for creating the views for each row. Here's an excerpt from an android development book at commonsware.com that might help.

1 Comment

I do have a SimpleCursorAdapter

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.