由网友(迟春)分享简介:我在Android的单选按钮组,看起来是这样的:选择颜色:红色蓝色橙色绿色我需要选择单选按钮,也是其价值所在。 我以这种方式4单选按钮内RadioGroup中 RG RB1A =(单选)findViewById(R.id.rb1a);RB1B =(单选)findViewById(R.id.rb1b);rb1c...![android 单选按钮对话框,Android单选按钮对话框用法实例分析](https://p.xsw88.cn/allimgs/daicuo/20230907/6529.png)
我在Android的单选按钮组,看起来是这样的:
选择颜色:
红色蓝色橙色绿色我需要选择单选按钮,也是其价值所在。
我以这种方式4单选按钮内RadioGroup中 RG
RB1A =(单选)findViewById(R.id.rb1a);RB1B =(单选)findViewById(R.id.rb1b);rb1c =(单选)findViewById(R.id.rb1c);rb1d =(单选)findViewById(R.id.rb1d);TV1 =(的TextView)findViewById(R.id.tv1);NEXT1 =(按钮)findViewById(R.id.next1);RG =(RadioGroup中)findViewById(R.id.rg);//我有错误这line.please帮助后,rg.setOnCheckedChangeListener(新OnCheckedChangeListener(){ 公共无效onCheckedChanged(RadioGroup中组,诠释checkedId) { } @覆盖 公共无效onCheckedChanged(CompoundButton为arg0,ARG1布尔){ // TODO自动生成方法存根 }});
解决方案
您可以测试使用 器isChecked()
功能radion按钮。
为前:
如果(radio1_red.isChecked()){ txtView.setText(红色按钮被选中);}
![android 单选按钮对话框,Android单选按钮对话框用法实例分析](https://p.xsw88.cn/allimgs/daicuo/20230907/6529.png)
看一看这个例。
您也可以参考这个页 - 表格的东西给在Android的SDK页。
执行此操作获取选定的单选按钮以及它的值:的
私人OnClickListener radio_listener =新OnClickListener(){ 公共无效的onClick(视图v){ //执行的点击行为 单选按钮RB =(单选)V; Toast.makeText(HelloFormStuff.this,rb.getText(),Toast.LENGTH_SHORT).show(); }};
I have a radio button group in Android which looks something like:
Choose Color:
Red Blue Orange GreenI need to get selected radio button and also its value.
I have 4 radiobuttons in this manner within radiogroup rg
rb1a=(RadioButton)findViewById(R.id.rb1a);
rb1b=(RadioButton)findViewById(R.id.rb1b);
rb1c=(RadioButton)findViewById(R.id.rb1c);
rb1d=(RadioButton)findViewById(R.id.rb1d);
tv1=(TextView)findViewById(R.id.tv1);
next1=(Button)findViewById(R.id.next1);
rg=(RadioGroup)findViewById(R.id.rg);
// I have error after this line.please help
rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId)
{
}
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
}
});
解决方案
you can test the radion button with the isChecked()
function.
for ex:
if(radio1_red.isChecked())
{
txtView.setText("Red button is checked");
}
Have a look at this Example .
You can also refer this Page - Form Stuff given in android-sdk pages.
Do this for getting selected radio button and also its value:
private OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};
相关推荐
最新文章