android - Move to Next Activity on Button click -
i have 2 buttons in fragment , on button click, displays toast want move activity.
here's code...
public class homefragment extends fragment implements view.onclicklistener { button btn,btn2; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_home, container, false); btn = (button) view.findviewbyid(r.id.btn); btn2 = (button) view.findviewbyid(r.id.btn2); btn.setonclicklistener(this); btn2.setonclicklistener(this); return view; } @override public void onclick(view v) { switch (v.getid()){ case r.id.btn: toast.maketext(this.getactivity(), "button 1!", toast.length_long).show(); break; case r.id.btn2: toast.maketext(this.getactivity(), "button 2 !", toast.length_long).show(); break; } } }
use intent navigation
replace:
@override public void onclick(view v) { switch (v.getid()){ case r.id.btn: intent intent = new intent(getactivity(),yourdestinationactivity.class); startactivity(intent); break; case r.id.btn2: intent intent = new intent(getactivity(),yourdestinationactivity.class); startactivity(intent); break; } }
Comments
Post a Comment