【发布时间】:2014-01-05 17:39:07
【问题描述】:
我正在创建一个简单的应用程序,其中有很多单选按钮,但我没有在其中使用文本,只添加背景图片。所以在我完成设计工作后,我需要做所有的机械工作。我的问题是我可以找到如何发送单选按钮文本的信息,但没有关于可能的图像发送的信息。我发现可以发送 ID,但我看到人们使用它作为 int 变量。我的单选按钮 ID 类似于 jobRB1、jobRB2、jobRB3、....,有些只是诸如 goodCar、badCar 之类的词。最令人困惑的部分。所以我的问题是如何将单选按钮 ID 读取为字符串,然后在将其发送到其他活动后再次设置为背景。
我只做研究,所以我现在除了要显示的 xml 文件之外没有任何代码。
一些代码(我希望它会有所帮助):
private RadioGroup firstRadioGroup;
private RadioGroup secondRadioGroup;
private RadioGroup thirdRadioGroup;
private RadioButton rb1,rb2,rb3,rb4,rb5;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_jobs_page);
firstRadioGroup = (RadioGroup) findViewById(R.id.jobrbgroup1);
secondRadioGroup = (RadioGroup) findViewById(R.id.jobrbgroup2);
thirdRadioGroup = (RadioGroup) findViewById(R.id.jobrbgroup3);
rb1 = (RadioButton) findViewById(R.id.jobRB1); rb2 = (RadioButton) findViewById(R.id.jobRB2);
rb3 = (RadioButton) findViewById(R.id.jobRB3); rb4 = (RadioButton) findViewById(R.id.jobRB4);
rb5 = (RadioButton) findViewById(R.id.jobRB5);
public void resetRadioButtons (View view){
firstRadioGroup.clearCheck();
secondRadioGroup.clearCheck();
thirdRadioGroup.clearCheck();
}
public void openReligionsPage (View view){
if(rb1.isChecked()){
Intent intent = new Intent (this, DisplayReligionsPage.class);
startActivity(intent);
}
else if(rb2.isChecked()){
Intent intent = new Intent (this, DisplayReligionsPage.class);
startActivity(intent);
}
else if(rb3.isChecked()){
Intent intent = new Intent (this, DisplayReligionsPage.class);
startActivity(intent);
}
else if(rb4.isChecked()){
Intent intent = new Intent (this, DisplayReligionsPage.class);
startActivity(intent);
}
else if(rb5.isChecked()){
Intent intent = new Intent (this, DisplayReligionsPage.class);
startActivity(intent);
}
【问题讨论】:
-
贴一些代码,让我们看看你到目前为止做了什么。
标签: android android-activity radio-button