I understand that you want to show a different context menu for short clicks and long clicks on the GridView element.
First, you just need to set the listener for a short click, since by default the behavior automatically displays a context menu for long clicks.
Then set the boolean flag to true in OnItemClickListener. The default value for long clicks is false.
Finally, in onCreateContextMenu (), check if it has a short click and display another context menu (standard) and set the flag to false. Else allows you to display the default context menu (options).
Here is some code to demonstrate the idea.
public class MainActivity extends Activity { private static final String[] arr = {"A", "B", "C", "D", "E", "F", "G", "H","I"}; private GridView mTGrid; private boolean isShort; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTGrid = (GridView) findViewById(R.id.gridView1); registerForContextMenu(mTGrid); mTGrid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { isShort = true; openContextMenu(view); } }); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.cell, arr); mTGrid.setAdapter(adapter); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; if(isShort) { getMenuInflater().inflate(R.menu.context_standard, menu); menu.setHeaderTitle("Standard Menu for "+arr[info.position]); isShort = false; } else { getMenuInflater().inflate(R.menu.context_options, menu); menu.setHeaderTitle("Options Menu for "+arr[info.position]); } } }
Sample application : You can download a sample application to see the behavior. GridExample_eclipse_project
source share