Я видел пример com.example.android.apis.view.List11 от ApiDemos. В этом примере каждая строка принимает представление android.R.simple_list_item_multiple_choice . Каждый такой вид имеет TextView
и CheckBox
.
Теперь я хочу, чтобы каждое представление имело 2 TextView
s и 1 CheckBox
, что немного похоже на пример List3 . Я попытался создать собственный файл макета row.xml, например:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/text_name"
android:textSize="13px"
android:textStyle="bold"
android:layout_toLeftOf="@id/checkbox"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text_phone"
android:textSize="9px"
android:layout_toLeftOf="@id/checkbox"
android:layout_below="@id/text_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Тогда в Activity
onCreate()
я делаю так:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Query the contacts
mCursor = getContentResolver().query(Phones.CONTENT_URI, null, null, null, null);
startManagingCursor(mCursor);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.row,
mCursor,
new String[] { Phones.NAME, Phones.NUMBER},
new int[] { R.id.text_name, R.id.text_phone });
setListAdapter(adapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
Результат выглядит так, как я хочу, но похоже, что список не знает, какой элемент выбран. Также мне нужно точно нажать на CheckBox
. В примере List11 мне нужно только щелкнуть строку товара.
Итак, что мне нужно сделать, чтобы создать список с множественным выбором с моим настраиваемым представлением для каждой строки? Большое спасибо.