Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I understand you want to show different context menu for short clicks and long clicks on a GridView item.</p> <p>First, you just need to set listener for short click since the default behavior will automatically show context menu on long clicks.</p> <p>Next, set a boolean flag to true in the OnItemClickListener. The default value is false for long clicks.</p> <p>Finally, in onCreateContextMenu() check if its a short click and show a different context menu (standard) and set flag to false. Else let it show the default context menu (options).</p> <p>Here is some code to demonstrate the idea.</p> <pre><code>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&lt;?&gt; parent, View view, int position, long id) { isShort = true; openContextMenu(view); } }); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(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]); } } } </code></pre> <p><strong>Sample Application</strong>: You can download a sample application to see the behavior. <a href="http://www.appsrox.com/shared/GridExample_eclipse_project.zip" rel="noreferrer">GridExample_eclipse_project</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload