【发布时间】:2016-08-30 18:32:59
【问题描述】:
试图让我的单选按钮工作,它们在一个组中,因此一次只能选择 1 个,但我想允许选择而不是触发选项,而是提交按钮收集结果,然后调用正确的方法这是我到目前为止所拥有的:
testRm.setOnClickListener(new Button.OnClickListener(
) {
@Override
public void onClick(View v) {
setReminder();
displayToast("Test");
}
});
setReminder 方法
public void setReminder() {
onewk = (RadioButton) findViewById(R.id.radioButton);
twowk = (RadioButton) findViewById(R.id.radioButton2);
onemnt = (RadioButton) findViewById(R.id.radioButton3);
mag = (RadioButton) findViewById(R.id.radioButton4);
twoprt = (RadioButton) findViewById(R.id.radioButton5);
if(onewk.isSelected()) {
scheduleNotification(getNotification("1 Week"), 7);
}
if(twowk.isSelected()) {
scheduleNotification(getNotification("2 Weeks"), 14);
}
if(onemnt.isSelected()) {
scheduleNotification(getNotification("1 Month"), 30);
}
if(mag.isSelected()) {
scheduleNotification(getNotification("Test 1"), 30);
}
if(twoprt.isSelected()) {
scheduleNotification(getNotification("Test 2"), 1);
}
}
吐司法
public void displayToast(String x) {
g1 = (RadioGroup) findViewById(R.id.rg1);
g2 = (RadioGroup) findViewById(R.id.rg2);
days = (EditText) findViewById(R.id.editText);
Toast.makeText(reminders.this, x, Toast.LENGTH_LONG).show();
g1.clearCheck(); g2.clearCheck(); days.setText("");
}
我可以在网上找到的唯一示例是在 onEvent 方法中使用 switch 语句,因此我尝试了其他方法但失败得很惨,因为从未调用 scheduleNotification 方法。
【问题讨论】:
标签: java android radio-button