开发者

How to inflate options menu from ponTouchEvent(MotionEvent me) in View

I have my menu which is called by clicking the button on android tablet. But I need to inflate the same menu by a click on view.

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater infl开发者_开发知识库ater = getMenuInflater();
    inflater.inflate(R.menu.options, menu);
    return true;
}

Any suggestions?


I called

mainActivity.openOptionsMenu();

from View. It worked!. the one Phil suggested creates a different menu. Not an option menu. any way thankx


You will want to use something like:

View myView = findViewById(R.id.my_view);
registerForContextMenu(myView);

in onCreate(...). Now when this View is clicked, it will open the context menu, and you can handle it in onCreateContextMenu(...). To be certain that this context menu has the same options as the main menu, you can inflate the same menu with the following code (though it will look like a Context Menu, not like the regular menu):

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜