2012-11-28 25 views
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); 
} 

感謝。

回答

0

以下是你需要的代碼:

yourRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

    @Override 
    public void onCheckedChanged(RadioGroup group, int checkedId) { 
     if(checkedId == yourRadioButtonWhichShouldBeChecked.getId()) { 
      yourMethodWhichShouldBeCalled(); 
     } 
    } 
}); 
+0

謝謝你,只是我需要的東西! –

+0

我很高興我能幫到你。請將此答案標記爲解決方案。 – Terel

相關問題