Andorid context menu

Source: Internet
Author: User

1.

// Register the context menu
RegisterForContextMenu (this. myconmentlist );

 

2.

Public boolean onContextItemSelected (MenuItem item ){
// TODO Auto-generated method stub
// AdapterContextMenuInfo lm = (AdapterContextMenuInfo) item. getMenuInfo ();
Switch (item. getItemId ()){
Case 1 ://

Break;
Case 2 ://

Case 3 ://

Break;
}
Return super. onContextItemSelected (item );
}

 

3

@ Override
Public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo ){
// TODO Auto-generated method stub
Super. onCreateContextMenu (menu, v, menuInfo );
// AdapterContextMenuInfo lm = (AdapterContextMenuInfo) menuInfo;
// If (lm. id! = 0 & lm. id! =-1 ){
Menu. setHeaderTitle ("function ");
Menu. add (1, 1, 1, "Reply to comment ");
Menu. add (1, 2, 2, "view User information ");
Menu. add (1, 3, 3, "View Original Dynamics ");
}
//}

 

4. Add the following code in the Adapter to implement the context menu of short press

ConvertView. setOnClickListener (new OnClickListener (){

@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
OpenContextMenu (v );
}
});

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.