android – listview setItemChecked不起作用

前端之家收集整理的这篇文章主要介绍了android – listview setItemChecked不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
由于某些原因setItemChecked不起作用.可以帮帮我修吗 @H_403_2@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);

这是列表项:

@H_403_2@<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"/>

请帮帮我.

解决方法

docs说:

Sets the checked state of the
specified position. The is only valid
if the choice mode has been set to
CHOICE_MODE_SINGLE or
CHOICE_MODE_MULTIPLE.

所以你可以尝试:

@H_403_2@list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

之前调用setItemChecked.

猜你在找的Android相关文章