Skip to content Skip to sidebar Skip to footer

Get Selected Radio Button Id Placed In Navigation View

I have taken radio group in the navigation view of drawer layout like this Copy

Handle the onClick event in code part

publicvoidonRadioButtonClicked(View view) {
    // Is the button now checked?boolean checked = ((RadioButton) view).isChecked();

    // Check which radio button was clickedswitch(view.getId()) {
        case R.id.radio_pirates:
            if (checked)
                // Pirates are the bestbreak;
        case R.id.radio_ninjas:
            if (checked)
                // Ninjas rulebreak;
    }
}

Solution 2:

Sorry couldn't answer in comment. Try this:

navigationView.getMenu().findItem(R.id.radioButtonId);

this will return Id of your RadioButton.

Edit:

Can you do something like this:

RadioButtonradio= (RadioButton)navigationView.findViewById(R.id.radioButtonId);

Post a Comment for "Get Selected Radio Button Id Placed In Navigation View"