Tôi có một lớp con tùy chỉnh DialogPreference
mà tôi muốn có một RadioGroup
với ba nút radio. Hai phần đầu tiên là các thành phần vani RadioButton
có tiêu đề, nhưng đối với phần thứ ba, tôi muốn đặt một số EditText
trực tiếp ở bên phải của nó để tôi có thể nhập giá trị tùy chỉnh khi nút đó được chọn.Thêm EditText cùng với RadioButton
Tôi đã thử đặt nút thứ ba vào ngang LinearLayout
cùng với EditText
nhưng sau đó nút thứ ba không tham gia vào số RadioGroup
mẹ nữa.
<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>
Tôi cũng đã thử thêm LinearLayout
này bằng chương trình nhưng vẫn có hành vi tương tự. Có cách nào để làm điều này, có lẽ bằng cách nói rõ ràng với phụ huynh RadioGroup
về nút thứ ba hoặc bằng cách nào đó định vị EditText
một cách thích hợp mà không sử dụng ngang LinearLayout
? Nếu không, tôi nghĩ rằng tôi sẽ phải viết một lớp con RadioButton
mà phải là một bữa tiệc thực sự!
gì về một RelativeLayout sau đó Linear chứa RadioGroup và sau đó chỉ cần đặt EditText bên cạnh RadioButton thứ ba dựa trên id của nó thuộc tính. – TronicZomB
Vì 'EditText' là chế độ xem hoàn toàn khác nên nó không thể là phần' RadioGroup'. Hoặc bạn có thể lập trình 'Enable' &' Disable' trong khi nút radio thứ ba được nhấp là cách để đạt được điều gì đó như thế này. Hy vọng bạn nhận được nó. –