6

I have dynamically generated ListView, which consists radio-buttons as list items.

Is it possible to use radiogroup functionality in that listview or for these radiobuttons.

I mean, I'd like, that if the user select a radio button the radio button selected before would deselected.

That is my solution at the moment, which I don't like very much. I just save selected radio button and if another one will be selected, deselect the saved one.

Thank you for your suggestions or links.

Here is my layout:

<?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"/>  

But I also tried with this one:

<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>
Tima
  • 12,765
  • 23
  • 82
  • 125
  • possible duplicate of http://stackoverflow.com/questions/4250599/android-listview-with-radiobutton-in-singlechoice-mode-and-a-custom-row-layout – Richard Le Mesurier Nov 04 '11 at 05:55
  • check out ItemRenderer.. set the item renderer in a list to whatever object yu want to display in the list... rajan... – Rajan Dec 03 '10 at 09:26

1 Answers1

2

I think you want android:choiceMode="singleChoice". It's a bit tricky to implement (I don't know the exact specifics myself), but it's a starting point.

Felix
  • 88,392
  • 43
  • 149
  • 167
  • 2
    thank you for starting point, but have no idea, where to start with?! – Tima Dec 06 '10 at 17:00
  • 2
    I usually just [search Google code search](http://google.com/codesearch?q=android:choiceMode%3D%22singleChoice%22) for other projects that use a specific feature and see how. Go on, click it :) – Felix Dec 07 '10 at 10:49
  • @Mur Votema if you consider this the correct answer, please mark it as accepted by clicking the checkmark to the left. – Felix Dec 22 '10 at 11:47