android – listview setItemChecked不起作用

前端之家收集整理的这篇文章主要介绍了android – listview setItemChecked不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
由于某些原因setItemChecked不起作用.可以帮帮我修吗
  1. String[] str = getResources().getStringArray(R.array.brush_type);
  2. sizeArrayAdapter = new ArrayAdapter<String>(this.getContext(),R.layout.drawing_list_item,str);
  3.  
  4. listType = SIZE_LIST;
  5. listView.setAdapter(sizeArrayAdapter);
  6.  
  7. // Populate the listView
  8. listView.setItemChecked(4,true);

这是列表项:

  1. <CheckedTextView
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/drawingCheckedTextView"
  4. android:layout_width="fill_parent"
  5. android:layout_height="?android:attr/listPreferredItemHeight"
  6. android:gravity="center_vertical"
  7. android:checkMark="?android:attr/listChoiceIndicatorSingle"
  8. android:background="@drawable/list_panel"
  9. android:paddingLeft="6dip"
  10. 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.

所以你可以尝试:

  1. list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

之前调用setItemChecked.

猜你在找的Android相关文章