Reputation: 2643
I'm trying to create a Fragment where the user can select the line width from 4 options. When they select one of the widths, I set the background with a blue highlight. Is it possible to use a radio group
with views
inside radio buttons
?
Currently this is how I'm doing it:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Checkbox test"
android:padding="16dp"
android:textColor="@color/colorBlack"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_selected_width_outline"
android:layout_margin="16dp">
<View
android:layout_width="match_parent"
android:layout_height="15dp"
android:background="@color/colorBlack"
android:layout_margin="32dp"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@color/colorBlack"
android:layout_margin="32dp"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/colorBlack"
android:layout_margin="32dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorBlack"
android:layout_margin="32dp"/>
</LinearLayout>
Upvotes: 0
Views: 108
Reputation: 21053
No its not possible . Check the source code of RadioGroup
it directly bypass the add View call to super
if if (child instanceof RadioButton)
is false . You can create a Custom group to act it like RadioGroup
by extending it from LinearLayout
.
Upvotes: 1