我有一个自定义的DialogPreference
子类,其中我想要有一个带有三个单选按钮的RadioGroup
。前两个是带有标题的简单RadioButton
组件,但对于第三个,我想将一个EditText
直接放在其右侧,以便在选择该按钮时输入自定义值。
我尝试将第三个按钮放入水平的LinearLayout
中,并与EditText
一起使用,但此时第三个按钮不再参与父级RadioGroup
。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:id="@+id/lactate_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/lactate_default_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_default_value"/>
<RadioButton
android:id="@+id/lactate_calibrated_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_calibrated_value" />
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/lactate_custom_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lactate_custom_value"/>
<EditText
android:id="@+id/lactate_custom_value_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</RadioGroup>
</LinearLayout>
我也尝试通过程序动态添加LinearLayout
,但仍然出现了相同的情况。是否有办法做到这一点,比如通过显式地告诉父RadioGroup
有第三个按钮,或者以某种方式适当地定位EditText
而不使用水平LinearLayout
?否则,我认为我将不得不编写一个RadioButton
子类,这应该是一场真正的派对!