6
我有动态生成的ListView,它包含单选按钮作为列表项。Android。在ListView中的RadioButtons
是否有可能在该列表视图或这些单选按钮中使用radiogroup功能。
我的意思是,如果用户选择一个单选按钮,之前选择的单选按钮将被取消选中。
这是我目前的解决方案,我不太喜欢。我只保存选定的单选按钮,如果选择另一个,则取消选择已保存的单选按钮。
感谢您的建议或链接。
这里是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="@+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="@color/black"
android:background="@color/transparent_white"/>
<ListView
android:id="@+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rb_lineId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:paddingLeft="50dp"
android:background="@drawable/selector_custombutton"/>
但我也试图与这一个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="@+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="@color/black"
android:background="@color/transparent_white"/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
可能的重复http://stackoverflow.com/questions/4250599/android-listview-with-radiobutton-in-singlechoice-mode-and-a-custom-row-layout – 2011-11-04 05:55:50
检查出ItemRenderer ..设置项目renderer在列表中的任何对象yu要在列表中显示... rajan ... – Rajan 2010-12-03 09:26:49