I am using Android to create an application. I have an activity where I create a options menu, for example below
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, menu);
return true;
}
The menu is loaded from an 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 I click on element 1, I use onOptionsItemSelected in my activity to work after clicking as follows:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.item1 :
return true;
default :
return super.onOptionsItemSelected(item);
}
}
So, when the user clicks on element 1, I would like to open the context menu. Firstly, I don’t know whether it is possible to open the context menu directly without using the hold position on the screen, as shown in several tutorials on the Internet.
If possible, how can I open the context menu in this way?
I thought to use registerForContextMenu()it openContextMenu()in the case of my element 1, but in what representation should I put the parameter?
- , , , .