ContextMenu for ListView

by Ankit Shah » Thu, 16 Jul 2009 03:48:12 GMT

Sponsored Links
 I have a ListActivity and using BaseAdapter i have populated ListItems
(Single ListItem row contains 3 views: 1 ImageView <"icon">, 1
TextView <"Title"> and 1 more TextView <"Description">).

Now When I short click on a list item, I get the position via
onListItemClick event. When I long click on the same listItem, the
context menu comes up. The thing is that there is no info on the
position (long click position/Index value).

I would like to get the selected item without requiring the user to
short click and then long click.

I have tried few things like getSelectedItem(), getSelectedItemId(),
and getSelectedItemPosition() but didn't work for me.

Help and Support would be greatly appreciated.

Thank You.

ContextMenu for ListView

by Mark Murphy » Thu, 16 Jul 2009 03:59:31 GMT


Sure there is.

Call getMenuInfo() on the MenuItem, and cast it to an
AdapterView.AdapterContextMenuInfo. You can then get the id of the item
that was clicked upon.

Here's a snippet of code from one of my book examples:

public boolean onContextItemSelected(MenuItem item) {
        switch (item.getItemId()) {
                case DELETE_ID:
                        AdapterView.AdapterContextMenuInfo info=



Mark Murphy (a Commons Guy)  | 

Looking for Android opportunities? 


Sponsored Links

ContextMenu for ListView

by Francesco B. » Fri, 31 Jul 2009 02:58:06 GMT

 Hi, I'm interested in this topic. I have a question about the id that
returns from Is this id the same that is used by SQLite? As I
see in your example, that I suppose is taken from the developers
tutorial, you use to delete an item from SQLite. But the
column in SQLite was named _id. Is this some kind of convention to
stick to? What if those items did not have an _id but a, suppose, _key
not called id? Could we do info.key?


Other Threads

1. ADC2 news ?

Are there any news on ADC 2?
I haven't seen any "client/scoring app" in the market ? How do people rate
submissions ?


2. simple notification crashing with "IllegalArgumentException"

onCreate() --
                nm = (NotificationManager) 

someOtherCall() --
                Notification notification = new Notification(R.drawable.icon, 
text", System.currentTimeMillis());
                nm.notify(NOTIFY_ID, notification);

crashes with "Illegal Argument Exception"



3. finishFromChild does not called

4. Android IMS support

5. SQLlite issue

6. Handling repo

7. USIM and ISIM Support