0

请帮助我了解如何在选中单选按钮后使用单选按钮执行方法,这是我的代码:

      if (RadioButton1.isChecked()){
                    UpdateResultsnewk();
                }else if (RadioButton2.isChecked()) {
                     UpdateResultsoldk();
                }


        public void UpdateResultsnewk(){
        int results1 = 100 + 10;
        Textview1.setText(results);

    }

 public void UpdateResultsoldk(){
    int results2 = 100 - 10;
    Textview2.setText(results);
 }

谢谢。

4

1 回答 1

0

Here is the code you need:

yourRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if(checkedId == yourRadioButtonWhichShouldBeChecked.getId()) {
            yourMethodWhichShouldBeCalled();
        }
    }
});
于 2012-11-28T12:12:29.640 回答