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. Maps API Key Signup page is down...



Not Found

The requested URL /android/add-ons/google-apis/signup.html?
agreeTerms=1&fp=... was not found on this server.


2. startActivity(intent) and ActivityNotFoundException

According to the doc, if the intent in startActivity(intent) is not
found, there will be an exception raised. Therefore I use a try/catch
block. However, even if I use a random string as the intent, the
promised exception does not occur.

Instead I see a dialog that says: "No application can perform this
function". I also get the same dialog if the intent is valid (picked
up by an app) but apparently doesn't want to act when the extras are
not what the app expects (e.g. my earlier question about
Intent.ACTION_SEND and mime types).

I am using the 1.5_r2 SDK on an AVD running 1.5, with the app running
at version 1.1 (sdk=2). Is this a doc error, a bug or am I
misunderstanding something? Can I simply delete the try/catch block?

3. Is it possible to theme the activity animation?

4. Strange Situation Debugging on G1

5. startActivity(intent) from Tab click works but Intent to class does not

6. How to launch ACTION_SENDTO intent with Intent.EXTRA_STREAM parameter

7. does android runs on OMAP5912 board ?