提交的Android单选按钮不起作用

时间:2016-05-05 04:56:28

标签: java android radio-button

尝试让我的单选按钮工作,它们在一个组中,因此一次只能选择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);
    }
}

Toast方法

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方法从未被调用过。

1 个答案:

答案 0 :(得分:2)

问题是[{1}}您需要检查其@model@model IEnumerable<AlexMusicStore.Models.Person> <div> @{ Html.RenderPartial("~/Views/Artists/UnderAge.cshtml", Model); } </div> 是否意味着

RadioButton而非checked