我正在使用 ListView 一次只能检查一个项目。这是我的自定义 list_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:textSize="20sp"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
/>
我使用普通数组适配器在 onCreate() 中填充列表:
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this, R.layout.list_row, strings);
myList.setAdapter(myAdapter);
显示列表时,我想让列表中的第 5 项显示为已选中。我该怎么做呢?我知道 CheckedTextView 有一个名为 setChecked() 的函数,但我怎样才能从列表中获取我的第 5 项以应用此函数呢?