Android: RadioGroup - How to configure the event listener

前端 未结 5 1115
北恋
北恋 2020-11-27 16:30

From my understanding, to determine if a checkbox is \"clicked\" and find if it\'s checked or not, code such as the following can be used:

cb=(CheckBox)findV         


        
5条回答
  •  半阙折子戏
    2020-11-27 16:55

    //Within the Activity that hosts this layout, the following method handles the click event for both radio buttons:
    
    public void onRadioButtonClicked(View view) {
    // Is the button now checked?
    boolean checked = ((RadioButton) view).isChecked();
    
    // Check which radio button was clicked
    switch(view.getId()) {
        case R.id.radio_pirates:
            if (checked)
                // Pirates are the best
            break;
        case R.id.radio_ninjas:                       
            if (checked)
                // Ninjas rule
            break;
    }
    }
    

提交回复
热议问题