在我的应用程序中,用户可以进行CRUD操作。 当用户输入数据时,有13个无线电组(选择的值是字符串格式)。完全输入数据后,用户可以将其保存到sqlite中。我的问题是,当用户点击编辑按钮时,我想知道返回所选单选按钮(之前用户检查过)的代码可以自动检查。
MainActivity中的代码:
rg1 = (RadioGroup) findViewById(R.id.rg1);
rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.rb_large:
palm_size="1";
// do operations specific to this selection
break;
case R.id.rb_average:
palm_size="2";
// do operations specific to this selection
break;
case R.id.rb_small:
// do operations specific to this selection
palm_size="3";
break;
case R.id.rb_vsmall:
// do operations specific to this selection
palm_size="4";
break;
}
}
});
获取字符串并在Edittext中显示的代码..
protected void onResume(){
super.onResume();
i=getIntent();
mark=i.getStringExtra("mark");
//jika berasal dari edit, maka tampilkan
if(mark!=null){
//id=i.getStringExtra("id");
et_estate.setText(i.getStringExtra("estate_name"));
et_manuring.setText(i.getStringExtra("manuring_block"));
et_year.setText(i.getStringExtra("year"));
et_record.setText(i.getStringExtra("record_date"));
et_bare.setText(i.getStringExtra("bare_soil"));
et_legume.setText(i.getStringExtra("legumes"));
et_lightgrass.setText(i.getStringExtra("light_grasses"));
et_fern.setText(i.getStringExtra("ferns"));
et_competitve.setText(i.getStringExtra("competitive"));
et_remarks_competitive.setText(i.getStringExtra("competitive_weed"));
//rg1=i.getStringExtra("yellowing");
et_remarks.setText(i.getStringExtra("remarks"));
id_assm=i.getStringExtra("id_assm");
}
}
如何通过此代码将所选单选按钮恢复到无线电组(rg1)? 帮助我。 感谢
答案 0 :(得分:0)
您可以保存id
的{{1}}而不是RadioButton
然后,您可以通过
value
和
intent.putExtra("idOfYourSelectedRadioButton", idOfYourSelectedRadioButton);
答案 1 :(得分:0)
我没有正确理解您的问题,但看起来您想要以编程方式检查单选按钮。可能会有所帮助
onResume:
rg1.check(R.id.rb_small)
其中R.id.rb_small可能是您要恢复的选中值
答案 2 :(得分:0)
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId){
case R.id.rb_large:
palm_size="1";
String rb_large="true";
// do operations specific to this selection
break;
case R.id.rb_average:
palm_size="2";
String rb_average="true";
// do operations specific to this selection
break;
case R.id.rb_small:
// do operations specific to this selection
palm_size="3";
String rb_small="true"
break;
case R.id.rb_vsmall:
// do operations specific to this selection
palm_size="4";
String rb_vsmall="true"
break;
}
这些字符串发送到第二个活动,然后检查哪个字符串为true,那些字符串为true表示单选按钮被选中,然后在oncreate中使用setChecked(true)方法自动为true