【发布时间】:2011-03-14 19:34:44
【问题描述】:
由于某种原因 setItemChecked 不起作用。有人可以帮我修 ti 吗?
String[] str = getResources().getStringArray(R.array.brush_type);
sizeArrayAdapter = new ArrayAdapter<String>(this.getContext(), R.layout.drawing_list_item, str);
listType = SIZE_LIST;
listView.setAdapter(sizeArrayAdapter);
// Populate the listView
listView.setItemChecked(4,true);
这是列表项:
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawingCheckedTextView"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:background="@drawable/list_panel"
android:paddingLeft="6dip"
android:paddingRight="6dip"/>
请帮帮我。
【问题讨论】:
-
你也必须实现 Checkable Interface。在这里查看我的答案:stackoverflow.com/a/19997650/1361494
-
CheckedTextView已经实现了它,如此处所述:developer.android.com/reference/android/widget/…An extension to TextView that supports the Checkable interface.
标签: android listview checkedtextview