列表视图setItemChecked不起作用 [英] listview setItemChecked doesn't work

查看:1243
本文介绍了列表视图setItemChecked不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因setItemChecked不起作用。可有一个人帮我解决TI?

For some reason setItemChecked doesn't work. can some one help me fix 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);

这就是列表项:

and this is the list item:

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

请帮我。

推荐答案

的<一个href="http://developer.android.com/reference/android/widget/AbsListView.html#setItemChecked%28int,%20boolean%29">docs这样说:

设定的选中状态   指定的位置。该才有效   如果选择的模式已被设置为   CHOICE_MODE_SINGLE或   CHOICE_MODE_MULTIPLE。

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.

所以,你可以试试:

list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

之前调用 setItemChecked

这篇关于列表视图setItemChecked不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆