ListView實現單選(一)

1 在ListView中添加
android:choiceMode="singleChoice"
如下:
<ListView
    android:id="@+id/list_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:choiceMode="singleChoice"
    >

</ListView>

2 在適配器中填充佈局的時候填充

android.R.layout.simple_list_item_single_choice
返回爲
CheckedTextView
如下:
CheckedTextView view = (CheckedTextView) (convertView == null ? 
LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_single_choice, parent, false) : convertView);
然後將view當成RadioButton來用即可


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章