当有多行时,java将RadioButton和EditText对齐在同一行上
我试图创建一个小列表(3行),其中水平排列的每行上有一个RadioButton
和一个EditText
视图。我希望单选按钮位于相同的RadioGroup
。我无法将单选按钮和编辑文本视图添加到linearlayout,因为Android会大喊该单选按钮有另一个父项。我怎样才能解决这个问题
我以编程方式添加每一行:
mAnswerGroup.addView(radioButton, new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mAnswerGroup.addView(editText, new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
# 1 楼答案
在这种情况下,
RadioGroup
将不起作用。您必须手动处理3RadioButtons
的已检查更改,因为您需要进行线性布局并在其中添加RadioButton
和EditText
。您必须手动取消选中其他单选按钮设置每个
RadioButton
的onCheckedChangeListener并手动处理: 在活动中实现OnCheckedChangeListener
接口,并在onCreate()
中执行此操作:然后,重写接口的
onCheckedChanged()
方法: