android - Open context menu by clicking on menu options item -
i use android make application. have activity create option menu below
@override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.mymenu, menu); return true; }
the menu loaded xml file :
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="item1" android:id="@+id/item1" /></menu>
when click on item 1, use onoptionsitemselected on activity work after click :
@override public boolean onoptionsitemselected(menuitem item) { switch(item.getitemid()) { case r.id.item1 : // here, open contextual menu return true; default : return super.onoptionsitemselected(item); } }
so, when user click on item 1 open contextual menu. first, don't know if it's possible open contextual menu directly without using hold position on screen several tutorials on internet show it.
if it's possible how can open contextual menu in way ?
i thought use registerforcontextmenu()
, opencontextmenu()
in case of item 1 view should put in parameter ?
if has idea way make that, know how must that.
if want have contextual menu, i'd use contextual menu designed in android doing long-press on given item. people accustomed , apps shouldn't differ in that.
the alternativ bit more complex. have menu loaded in separate activity style dialog window (you know faded half-transparent background). can done applying theme.dialog
style activity in manifest.xml file:
<activity android:name=".activities.tagpopupactivity" android:label="tagging" android:theme="@android:style/theme.dialog"> ... </activity>
alternatively can directly create dialog window described here. context (i.e. list click) implementing appropriate click listener in main list activity , when user clicks on item, retrieve id , package bundle forward "menu"-activity styled popup dialog.
Comments
Post a Comment