I have taken radio group in the navigation view of drawer layout like this
<android.support.design.widget.NavigationView
app:headerLayout="@layout/header"
app:menu="@menu/drawer">
<RadioGroup>
<RadioButton/>
<RadioButton/>
</RadioGroup>
</android.support.design.widget.NavigationView>
I want to get the selected radio button text or id but I am not getting any logs or Toast and no errors also..
Code for getting selected radio button:
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int pos=rg.indexOfChild(findViewById(checkedId));
Toast.makeText(MainActivity.this, "ID = "+String.valueOf(pos),
Toast.LENGTH_SHORT).show();
Log.e("",""+pos);
}
I know I can achieve this by using custom list view.. But how to get this working..
Example - just like provided in developer.android
You just need to add attribute onClick in xml file like below
Handle the onClick event in code part
Sorry couldn't answer in comment. Try this:
this will return Id of your
RadioButton
.Edit:
Can you do something like this: