如何从多个单选组传递单选按钮值?如何解决返回第一个值?
Posted
技术标签:
【中文标题】如何从多个单选组传递单选按钮值?如何解决返回第一个值?【英文标题】:How to pass radio button values form multiple radio groups?how to solve returning the first value? 【发布时间】:2019-09-02 11:01:34 【问题描述】:screenshot 如何从多个无线电组中获取值以及如何解决仅返回第一个值
public void onClick(View v)
int widepart=radioWidePart.getCheckedRadioButtonId();
int jawShape=radioJawShape.getCheckedRadioButtonId();
int faceLength=radiofaceLength.getCheckedRadioButtonId();
RadioButton foreheard = (RadioButton)findViewById(widepart);
RadioButton cheekbones = (RadioButton)findViewById(widepart);
RadioButton pointy=(RadioButton)findViewById(jawShape);
RadioButton square=(RadioButton)findViewById(jawShape);
RadioButton flshort=(RadioButton)findViewById(faceLength);
RadioButton flaverage=(RadioButton)findViewById(faceLength);
if(foreheard.isChecked())
if(pointy.isChecked())
if(flshort.isChecked())
Intent Intents=new Intent(form.this,heart.class);
startActivity(Intents);
setContentView(R.layout.activity_heart);
else if(flaverage.isChecked())
Intent Intents=new Intent(getApplicationContext(),heart.class);
startActivity(Intents);
setContentView(R.layout.activity_heart);
【问题讨论】:
你能解释一下你的代码没有什么吗?什么是不受欢迎的行为? 我想从多个radioGroups 中获取值,例如分别为foreheard 和pointy 形式的widepart 组和jawshape 组。我想根据多个组中选中的单选按钮进入下一个活动。当前代码只返回第一个值。 【参考方案1】:final RadioGroup radioWidePart= (RadioGroup) findViewById(R.id.widestpart);
final RadioButton forehead=(RadioButton)findViewById(R.id.foreheard);
final RadioButton cheekbone=(RadioButton)findViewById(R.id.cheekbone);
final RadioGroup radioJawShape=(RadioGroup) findViewById(R.id.shapeOfJaw);
final RadioButton pointy=(RadioButton)findViewById(R.id.pointy);
final RadioButton square=(RadioButton)findViewById(R.id.square);
final RadioGroup radiofaceLength=(RadioGroup)findViewById(R.id.faceLength);
final RadioButton flshort=(RadioButton)findViewById(R.id.flshort);
Button btnSubmit=(Button) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new View.OnClickListener()
public void onClick(View v)
if(pointy.isChecked())
Intent Intents= new Intent(form.this, heart.class);
startActivity(Intents);
【讨论】:
以上是关于如何从多个单选组传递单选按钮值?如何解决返回第一个值?的主要内容,如果未能解决你的问题,请参考以下文章
如何检查单选按钮是不是在 Android 的单选组中被选中?
如何通过 Node + Express + Mongoose 中的单选按钮传递布尔值?