You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Radio buttons - waiting for the button click before processing
publicclassMainActivityextendsActivity {
RadioGroupradiogroup;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Connect the radioGroupradiogroup = (RadioGroup) findViewById(R.id.radioGroup);
// Connect the buttonButtonbtn = (Button) findViewById(R.id.btn);
// Adding a listenerbtn.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(Viewv) {
// retrieve the radio button that was selectedintradioSelected = radiogroup.getCheckedRadioButtonId();
// get the text associated with that radioIdRadioButtonselected = (RadioButton) findViewById(radioSelected);
// Show a toast/** * See the difference between the two toasts below **/// Toast.makeText(getBaseContext(), selected+"",// Toast.LENGTH_SHORT).show();Toast.makeText(getBaseContext(), selected.getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}