julius wrote:
> I have a ListView which is populated with items and I would like to be
> able to create the context menu based on some information fetched from
> the Cursor used to create the row. Is there a preferred approach for
> storing a boolean or flag associate with the row?

You could use setTag() on the row View, if that is not being used for
something else.

However, you probably don't need to use that -- see below.

> Eg. should it be in
> the View? I could make the decision when creating the menu too, but I
> need to get a unique id from the row in the ListView
> 
>       public void onCreateContextMenu(ContextMenu menu, View v,
> ContextMenuInfo menuInfo) {

Cast the menuInfo to an AdapterView.AdapterContextMenuInfo. You then
have access to the position of the row within your result set, and the
ID of the row (if you are using CursorAdapter or otherwise have row IDs).

> Also listView.getSelectedItem() seems to return null,
> listView.getSelectedItemId() gives a very negative number and
> listView.getSelectedView() is null too.

Those will only be valid if a row is selected:

http://developer.android.com/resources/articles/touch-mode.html

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.6 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to