Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get location (on screen) of row in listview
    primarykey
    data
    text
    <p>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.</p> <pre><code>public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; 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); } } </code></pre> <p>I want to display a view over the top of the swiped row with a set of context sensitive options for that row.</p> <p>My problems is that the following methods:</p> <pre><code>v.getTop() v.getBottom() </code></pre> <p>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.</p> <p>The methods below seem to suffer from the same problem...</p> <pre><code>v.getLocationOnScreen(loc) v.getLocationInWindow(loc) </code></pre> <p>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).</p> <p>Any help would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload