Android Radio Buttons -
i developing android application , have run slight problem. on questions when user clicks either yes or no followed next button need go different page, code seems incorrect can please help.
thanks in advance.
below code:
public void next_btn3(view view){ boolean checked = ((radiobutton)view).ischecked(); switch (view.getid()){ case r.id.yes_3: if (checked) new intent(this, questionnaire4.class); startactivity(detailintent); break; case r.id.no_3: if (checked) new intent(this, questionnaire6.class); startactivity(detailintent); break; } }
in code, declare intent without assigning it. forgot use brackets around if body. lastly, have casted clicked button radiobutton, should instead found using findviewbyid(r.id.radio_id_here) ; try this:
public void next_btn3(view view){ boolean checked = ((radiobutton)view).ischecked(); //must find radiobutton through id, not cast clicked button radio button switch (view.getid()){ case r.id.yes_3: if (checked) { intent detailintent = new intent(this, questionnaire4.class); startactivity(detailintent); } break; case r.id.no_3: if (checked) { intent detailintent = new intent(this, questionnaire6.class); startactivity(detailintent); } break; } }
Comments
Post a Comment