listView setItemchecked不起作用
-
24-10-2019 - |
题
由于某种原因,设置检查不起作用。有人可以帮助我修复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"/>
请帮我。
解决方案
这 文档 说这个:
设置指定位置的检查状态。 The is only valid if the choice mode has been set to CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE.
因此,您可以尝试:
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
打电话之前 setItemChecked
.
不隶属于 StackOverflow