2010-12-03 9 views
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> 
+0

可能な複製http://stackoverflow.com/questions/4250599/android-listview-with-radiobutton-in-singlechoice-mode-and-custom-row-layout –

+0

ItemRendererをチェックアウトする..アイテムを設定するあなたがリストに表示したいどんなオブジェクトにリスト内のレンダラ... rajan ... – Rajan

+0

それはAndroidのものですか? – Tima

答えて

2

私はあなたがandroid:choiceMode="singleChoice"をしたいと思います。実装するのはちょっと難しいです(私は正確な内容はわかりませんが)、それは出発点です。

+2

出発点をありがとうが、どこから始めるべきかわからない! – Tima

+2

私は通常、特定の機能を使用する他のプロジェクトの[Googleコード検索を検索](http://google.com/codesearch?q=android:choiceMode%3D%22singleChoice%22)です。行って、それをクリックしてください:) – Felix

+0

Ooo、リンクありがとう! – Tima