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"