Android menu item list navigation -
i need please me switch , case...
i have 3 item in action bar item1, item2, item3 , have 3 activity item1activity.java, item2activity, item2activity.. want call activity menu when item selected..
public class mainactivity extends activity { /** array of strings populate dropdown list */ string[] actions = new string[] { "item1", "item2", "item3" }; protected int position; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); /** create array adapter populate dropdownlist */ arrayadapter<string> adapter = new arrayadapter<string>(getbasecontext(), android.r.layout.simple_spinner_dropdown_item, actions); /** enabling dropdown list navigation action bar */ getactionbar().setnavigationmode(actionbar.navigation_mode_list); /** defining navigation listener */ actionbar.onnavigationlistener navigationlistener = new onnavigationlistener() { @override public boolean onnavigationitemselected(int itemposition, long itemid) { switch (itemposition) { case 1: intent = new intent(); i.setclass(getapplicationcontext(), item1activity.class); startactivity(i); return true; case 2: intent = new intent(); i.setclass(getapplicationcontext(), item2activity.class); startactivity(i); return true; } } }; /** setting dropdown items , item navigation listener actionbar */ getactionbar().setlistnavigationcallbacks(adapter, navigationlistener); }
}
use mainactivity.this instead of getapplicationcontext()
activity child of context
Comments
Post a Comment