1

I am looking for a way to open a ContextMenu "under" an item in a ListView. An example of this implementation can be found in the "reddit is fun" android app. I have attached a screen shot for your reference.

screenshot

I have been trying to achieve this for quite a long time but have been unsuccessful. How can I achieve this functionality?

I think it is a very nice way of showing a context menu and I'd like to use this technique too!

zeiger
  • 700
  • 5
  • 16
  • 3
    I would implement that extra menu directly in the row layout. – user Sep 14 '12 at 10:59
  • @Luksprog I will try this tonight. But I suspect that when I scroll through the `ListView`, it will re-use this menu for another list item and if I have modified the menu to show, lets say, "Unsave" instead of "Save" for an earlier item, it will incorrectly show "Unsave" for the new item (because the views are reused during the `ListView`scrolling) – zeiger Sep 14 '12 at 11:06
  • That will not happen if you take care to show the correct status of each row(which is something you should already do, when using a `ListView`). You just have to "store" and remember the correct state of each row. Depending on your current row data this could be something really simple to do. – user Sep 14 '12 at 11:09
  • I've adapted some old code to show you how you might do what I said above. You can find it here https://gist.github.com/3722950 ; – user Sep 14 '12 at 16:15
  • @Luksprog could yo please post both your comments as an answer so I can accept it as the correct answer? Your idea about implementing the menu layout directly in the row layout worked and the sample code you provided was enough for me to get it working. Thanks! – zeiger Sep 14 '12 at 23:32

3 Answers3

2

That menu could be implemented directly in the row layout. You'll have to add to your current layout the extra menu layout(and hide it at first, you probably don't want to show it when the user first works with the ListView). All you have to then is to add the logic to show/hide the menu and also keep track of what is happening with the menu itself(in a custom adapter) and the items in it(like it the menu is open/ closed, the status of the items in it). You can find a simple sample about how to do this here: https://gist.github.com/3722950 .

user
  • 86,916
  • 18
  • 197
  • 190
0

Use PopupWindow to hold your context menu items. Popup window can easily be positioned on the screen. More on PopupWindow can be found here, or google for tutorials on that subject.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • I am not sure how to ensure that the `PopupWindow` will appear exactly under the item in the ListView. I don't want a floating container appearing on top of the view currently in the foreground – zeiger Sep 14 '12 at 10:59
  • You can do pixel precise positioning. So all you need is to get screen position of the row view. See http://stackoverflow.com/questions/2139700/how-to-get-location-on-screen-of-row-in-listview – Marcin Orlowski Sep 14 '12 at 11:36
0

Can you use UitabBarController with tabBars as share,save hide,comments like that.then after what we click the tab the particular list view will displayed.

Vaddi
  • 27
  • 6
  • I don't understand what you mean. Do you mean I should add action bar icons for these actions on clicking an item in the `ListView`? That is not what I want to achieve. – zeiger Sep 14 '12 at 11:03
  • You mean ,you want to add context menu under each item in list view? – Vaddi Sep 14 '12 at 12:28
  • Yes, I need to add a context menu under each item – zeiger Sep 14 '12 at 15:11