Android popup Menu Box "Brochure context Menu"

Source: Internet
Author: User

Brochure context Menu: (Long Press to pop up a menu)


The first method of creation (combined with long-press events):


public class Mainactivity extends Activity {
Private TextView Username,password;
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Username = (TextView) Findviewbyid (r.id.username);
Password = (TextView) Findviewbyid (R.id.password);


Username.setoncreatecontextmenulistener (New Oncreatecontextmenulistener () {


@Override
public void Oncreatecontextmenu (ContextMenu menu, View V,
Contextmenuinfo menuinfo) {
TODO auto-generated Method Stub
Menu.add ("file");
Menu.add ("edit");
Menu.add ("source");


}
});




}
@Override
public boolean oncontextitemselected (MenuItem item) {
TODO auto-generated Method Stub
Run when menu context element is selected
Toast.maketext (this, item.gettitle () + "oncontextitemselected", 1). Show ();
return super.oncontextitemselected (item);
}
@Override
public boolean onmenuitemselected (int featureid, MenuItem item) {
TODO auto-generated Method Stub
Run when a menu element is selected
Toast.maketext (this, item.gettitle () + "onmenuitemselected", 1). Show ();
Return super.onmenuitemselected (Featureid, item);
}
}






Another method:
(Note the context menu)




public class Mainactivity extends Activity {
Private TextView Username,password;
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Username = (TextView) Findviewbyid (r.id.username);
Password = (TextView) Findviewbyid (R.id.password);


This.registerforcontextmenu (username);//Brochure Menu
}
@Override
public void Oncreatecontextmenu (ContextMenu menu, View V,
Contextmenuinfo menuinfo) {
TODO auto-generated Method Stub
Menu.add ("file");
Menu.add ("edit");
Super.oncreatecontextmenu (menu, V, menuinfo);
}
@Override
public boolean oncontextitemselected (MenuItem item) {
TODO auto-generated Method Stub
Run when menu context element is selected
Toast.maketext (this, item.gettitle () + "oncontextitemselected", 1). Show ();
return super.oncontextitemselected (item);
}
@Override
public boolean onmenuitemselected (int featureid, MenuItem item) {
TODO auto-generated Method Stub
Run when a menu element is selected
Toast.maketext (this, item.gettitle () + "onmenuitemselected", 1). Show ();
Return super.onmenuitemselected (Featureid, item);
}
}

Android popup Menu Box "Brochure context Menu"

Related Article

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.