Question

My idea is to have pairs ImageView - RadioButton, each pair enclosed in LinearLayout (horizontal orientation) and ImageButtons have their background color changed when an option is selected and confirmed. So, it would look like:

[LinearLayout1]: [ImageView1] [RadioButton1]
[LinearLayout2]: [ImageView2] [RadioButton2]
[LinearLayout3]: [ImageView3] [RadioButton3]

Is it possible to store this hierarchy within RadioGroup? I tried to apply this but see no ImageViews in my app. Or is RadioGroup built only for RadioButtons and all other views are ignored?

Was it helpful?

Solution

Yes, it's possible. If it's not working, there's something else wrong with your code.

A proof of concept layout based on the ApiDemos sample Android app included in the SDK:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:checkedButton="@+id/lunch"
    android:id="@+id/menu">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_group_1_breakfast"
        android:id="@+id/breakfast"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/btn_star"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/radio_group_1_lunch"
            android:id="@id/lunch"/>
    </LinearLayout>

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_group_1_dinner"
        android:id="@+id/dinner"/>


    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_group_1_all"
        android:id="@+id/all"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_group_1_selection"
        android:id="@+id/choice"/>
</RadioGroup>

and the layout it produces:

Radio buttons

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top