10
我正在使用ListView,其中一次只能檢查一個項目。 這是我的自定義list_row.xml:Android:我如何檢查Checked ListView中的特定項目?
<?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);
當顯示列表,我希望有,比方說,列表中的第五項顯示爲已選中。我怎麼能這樣做呢?我知道CheckedTextView有一個名爲setChecked()的函數,但是我怎樣才能從列表中獲得我的第五項來應用這個函數呢?