Java 在tablelayout Android中排列单选按钮
我想在多行和多列的表格布局中排列单选按钮,控件是使用下面的代码排列的,但不能在同一个单选按钮组中关联 你能帮忙吗,下面是我试过的代码Java 在tablelayout Android中排列单选按钮,java,android,radio-button,Java,Android,Radio Button,我想在多行和多列的表格布局中排列单选按钮,控件是使用下面的代码排列的,但不能在同一个单选按钮组中关联 你能帮忙吗,下面是我试过的代码 <TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioGroup android:id="@+id/radioLang1"
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioGroup
android:id="@+id/radioLang1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerPadding="0dp"
android:orientation="vertical" >
<TableRow>
<RadioButton
android:id="@+id/radioEnglish1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:checked="true"
android:onClick="onRadioButtonClicked"
android:text="@string/lang1"
android:textColor="@android:color/black"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radioTransliteration"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:checked="true"
android:onClick="onRadioButtonClicked"
android:text="Punjabi Transliteration"
android:textColor="@android:color/black"
android:textSize="12sp" />
</TableRow>
<TableRow>
<RadioButton
android:id="@+id/radioPunjabi1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:onClick="onRadioButtonClicked"
android:text="Punjabi Vyakhya(Meaning)"
android:textColor="@android:color/black"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radioHindi"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:onClick="onRadioButtonClicked"
android:text="Hindi Mein Padhiye"
android:textColor="@android:color/black"
android:textSize="12sp" />
</TableRow>
<RadioButton
android:id="@+id/radioEnglishTranslation1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:onClick="onRadioButtonClicked"
android:text="@string/eng_translate"
android:textColor="@android:color/black"
android:textSize="12sp" />
</RadioGroup>
</TableLayout>
谢谢
Amandeep我也有同样的问题,但据我所知,不可能像你所尝试的那样去做 我搜索了一下,找到了一个可能的解决办法
- 子类表布局()
或者,如果您有时间更改布局,请使用RelativeLayout。不幸的是,我在完成整个布局后发现了这个问题。改变并不难,但对于我所需要的,上面的“解决方法”是有效的,对于这个项目,这样做是可以的。创建一个RadioGroup类和RadioButton类,然后应用到xml将是最简单的方法
看这个我回答了你同样问题的更一般的版本 要点是将单选按钮视为常规按钮,并自行处理切换。它不像设计良好的单选按钮系统那样优雅,但我认为它比制作定制小部件更简单。我们必须用我们所拥有的来工作
class FooActivity {
RadioButton m_one, m_two, m_three;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
m_one = (RadioButton) findViewById(R.id.first_radio_button);
m_two = (RadioButton) findViewById(R.id.second_radio_button);
m_three = (RadioButton) findViewById(R.id.third_radio_button);
m_one.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(true);
m_two.setChecked(false);
m_three.setChecked(false);
}
});
m_two.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(false);
m_two.setChecked(true);
m_three.setChecked(false);
}
});
m_three.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(false);
m_two.setChecked(false);
m_three.setChecked(true);
}
});
...
} // onCreate()
}
你可能想看看下面的链接:非常感谢。为了实现这一目标,我从早上开始就绞尽脑汁。它就像一个符咒:)
class FooActivity {
RadioButton m_one, m_two, m_three;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
m_one = (RadioButton) findViewById(R.id.first_radio_button);
m_two = (RadioButton) findViewById(R.id.second_radio_button);
m_three = (RadioButton) findViewById(R.id.third_radio_button);
m_one.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(true);
m_two.setChecked(false);
m_three.setChecked(false);
}
});
m_two.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(false);
m_two.setChecked(true);
m_three.setChecked(false);
}
});
m_three.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_one.setChecked(false);
m_two.setChecked(false);
m_three.setChecked(true);
}
});
...
} // onCreate()
}