Preliminary understanding of menu items

Source: Internet
Author: User

public class Mainactivity extends Appcompatactivity {private TextView TextView;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);    TextView = (TextView) Findviewbyid (; } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio        n Bar if it is present.        Add a menu//Getmenuinflater () by adding the XML method statically. Inflate (, menu); Method Two, adding the code dynamically add the menu item MenuItem item = menu.add (1, 100, 1, "Zhao 1");        Parameters (GroupID, ItemID, order, title) Item.settitle ("AAA");        Menu.add (1,101,1, "Zhao 2");        Menu.add (1,102,1, "Zhao 3");                Menu.add (1,5,1, "Zhao 4");    return true; } @Override public boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The action bar would//automatically handle clicks on the Home/up button, so Long/As you specify a the parent activity in Androidmanifest.xml.        int id = item.getitemid (); Noinspection simplifiableifstatement switch (ID) {case 100:{Intent Intent = new Intent                (Mainactivity.this,second_demo.class); Item.setintent (Intent);                Jump to other activity Textview.settext ("clicked" + ID);            Break                } Case 101:{Textview.settext ("clicked" + ID);            Break                } Case 102:{Textview.settext ("clicked" + ID);            Break                } Case 5:{Textview.settext ("clicked" + ID);            Break    }} return super.onoptionsitemselected (item); }}


Preliminary understanding of menu items

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.