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

 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;
    }
}

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:

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

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