Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Context menu on single click

Tags:

I have an Intent that extends a ListActivity. In my onCreate method after having populated the list adapter I use registerForContextMenu(getListView()); to register for a context menu.

Now it is working and the context menu has its original function which is; once I click and hold down on an item the context menu opens.

Can I open the context menu on a single click (without having to hold down on the list)?

All help is appreciated.

like image 364
Adnan Avatar asked Jun 22 '11 04:06

Adnan


1 Answers

Here is another simpler way to show context menu on single click.

private void addOnClickListener() {     contactList.setOnItemClickListener(new AdapterView.OnItemClickListener()     {         public void onItemClick(AdapterView<?> parent, View view, int position, long id)         {               view.showContextMenu();         }     }) } 

replace contactList by your ListView and make sure to call this method after the initialization of ListView.

like image 96
Pawan Maheshwari Avatar answered Sep 20 '22 20:09

Pawan Maheshwari