Pro Android learning notes (S3.): Menu (3): Context Menu

Source: Internet
Author: User

YesOne and only one ContextMenu can be created. Check whether the mouse is long-pressed Based on view. Therefore, the number of views in an activity can be as many as the number of contextmenus.

SetContentView (R. layout. pure_text );

 

RegisterForContextMenu
(InfoTv );
}


Public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo){


Menu.SetHeaderIcon(R. drawable. leaf );
Menu.SetHeaderTitle("Context Menu :");
Menu.Add(Menu. NONE,, TV _CONTEXTMENU_BASE, "Item.1 ");
Menu.Add(Menu. NONE, TV _CONTEXTMENU_BASE + 1,, "Item.2 ");

SubMenu. setHeaderIcon (R. drawable. clock );
SubMenu. add (Menu. NONE, TV _CONTEXTMENU_BASE + 100, + TV _CONTEXTMENU_BASE + 100, "sub.1 ");
SubMenu. add (Menu. NONE, TV _CONTEXTMENU_BASE + 101, + TV _CONTEXTMENU_BASE + 101, "sub.2 ");
}

Public boolean onContextItemSelected (MenuItem item){
If (Item. getItemId ()= TV _CONTEXTMENU_BASE ){

} Else {

}
Return super. onContextItemSelected (item );
}

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: info-contact@alibabacloud.com 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.