Displaying a drop-down PopupWindow when a ListView item is clicked, then scrolling the ListView?

StackOverflow https://stackoverflow.com/questions/23519587

  •  17-07-2023
  •  | 
  •  

Question

When the PopupWindow is displayed and the ListView is scrolled, so that the anchoring item is out of the window, the View of that item gets recycled by the Adapter. Then the PopupWindow starts jumping around the screen because it doesn't know where's its original anchor located.

Is there a correct way to overcome this problem?

Was it helpful?

Solution 2

A possible solution is as follows:

  1. A grandparent of the anchor view is the view returned by Adapter.getView(). Upon showing a PopupWindow as drop-down, store a flag in the grandparent's tag. Also store a reference to this gandparent, and the selected item id.
  2. In Adapter.getView(), when the requested item id equals the selected item id, use PopupWindow.update() to attach the popup to the new view. Remove the tag from the old grandparent and update the grandparent reference.
  3. In Adapter.getView() if you get a convertView which has the flagged tag, and the requested item id differs from the selected item id, use PopupWindow.update() to un-attach the popup from the grandparent. Set the grandparent to null.

This is a bit complicated so I haven't tried it yet, but it should work and I'm writing it here in case someone's interested.

OTHER TIPS

Ideally I think displaying PopupWindow is not the correct solution.

Anyway if you have that in place already, the list scroll should dismiss the PopupWindow because keeping it dosen't makes sense as you have already scrolled the list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top