I have implemented some gesture detection code so that I can detect when a row in my listview (which is situated in a FrameLayout) has been swiped.
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
int itemId = MainActivity.this.getListView().pointToPosition((int) e1.getX(),(int) e1.getY());
Offer order = (Offer)MainActivity.this.getListView().getAdapter().getItem(itemId);
View v = MainActivity.this.getListView().getChildAt(itemId);
}
}
I want to display a view over the top of the swiped row with a set of context sensitive options for that row.
My problems is that the following methods:
v.getTop()
v.getBottom()
return correct values only before the view has been scrolled. I could probably do some calculation to work out offsets using scroll positions etc but I also noticed that I only get values when I swipe a row that is visible on screen to begin with. If I scroll down the list and then swipe a row (that was not originally off-screen) then these methods return null values.
The methods below seem to suffer from the same problem...
v.getLocationOnScreen(loc)
v.getLocationInWindow(loc)
Ultimately, I am looking to find the distance between the top of the visible listView and the row that has been swiped. I will then use this distance to add a view to the parent FrameLayout with the appropriate height padding (so that it covers the swiped row).
Any help would be much appreciated!