views:

1104

answers:

1

Hi,

I have created an application for Android that has an activity that has a ListView which lists all current users (each row is just an image of their profile along with some text with their current status and username).

I have added a contextmenu, so that a long-click brings up several options such as "view profile", "send message", etc.

In the ContextMenu handler, how can I extract information to know which user the context menu has been clicked for (for example, if i select userX and then selected "view profile" then it would need to be able to retrieve the userX object and load the profile)

As the row currently only has descriptive text set, would i need to also embed some other hidden user ID or something? any thoughts on how i could set/retrieve such data?

Thanks

A: 

Start here:

http://stackoverflow.com/questions/2321332/detecting-which-selected-item-in-a-listview-spawned-the-contextmenu-android

http://stackoverflow.com/questions/433761/how-do-you-implement-context-menu-in-a-listactivity-on-android

Also, here is a sample project that demonstrates getting the _ID of a database row in support of a "Delete" context menu item.

CommonsWare
I am trying the sample project you mentioned: how do you hide the ID numbers, and how do you make the listview to be bigger to fill the screen. http://img138.imageshack.us/img138/6920/ss4na.jpg I am trying to do as big as here: http://stackoverflow.com/questions/2350912/why-this-android-view-doesnt-fill-the-screen-vertically
Pentium10
Thanks for the answer - I had found some reference to use the AdapterContextMenuInfo object, however, is it possible to pre-set the ID of the row?For example, once I have the row ID would I then be able to load the user object from that? (e.g. if the row just has the user's screenname and profile description and no unique identifier displayed) - Would it be possible to attach a user object to the row that once I have the row ID I can retrieve? Thanks
rhinds
"is it possible to pre-set the ID of the row?" The `_ID` comes from the `Cursor`. Where the `Cursor`'s data comes from (SQLite, `ContentProvider`, something else) is up to you.
CommonsWare