Yuhao_Zhu
Yuhao_Zhu

Reputation: 161

ListView with checkbox - why the checkbox doesn't show?

I'm using the ListView to provide a list for the user to choose from.

Here is the main code:

SimpleAdapter adapter = new SimpleAdapter(this,contacts, R.layout.list_contact,
                                          from_contacts, to_contacts);
listview_selected_contact.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listview_selected_contact.setAdapter(adapter);

I wonder why the checkbox doesn't show? The program run properly just without the visible checkbox. Can anyone help?

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/username"></TextView>

</LinearLayout>

Upvotes: 1

Views: 930

Answers (2)

QuickNick
QuickNick

Reputation: 1931

It looks like that your R.layout.list_contact isn't CheckedTextView.

See source of android.R.layout.simple_list_item_multiple_choice

I can recommend you to build custom view which is child of any ViewGroup classes and implementator of interface Checkable.

Upvotes: 2

Shailendra Singh Rajawat
Shailendra Singh Rajawat

Reputation: 8242

id of checkBox and listView in R.layout.list_contact should be specific .

so follow ApiDemoes multiple List example for both layout and java code .

Upvotes: 0

Related Questions