title: Showing a delete button on swipe in a listview for Android
body: <p>Expanding on another Stackoverflow question, I've implemented some gesture detection code so that I can detect when a row in my listview (which is in a FrameLayout) has been swiped.  I followed the question/answer by Damian here about how to get the individual row/view from the adapter.
  <a href="https://stackoverflow.com/questions/2139700/how-to-get-location-on-screen-of-row-in-listview">How to get location (on screen) of row in listview</a></p>
  
  <p>I have code in my onFling that gets the view for the row, and tries to make a delete button that is set as invisible in my xml layout to visible.  However, this doesn't happen.  I was wondering how I make a button visible in a listview on a swipe?</p>
  
  <pre><code>class MyGestureDetector extends SimpleOnGestureListener {
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
          try {
  
              if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE
                      &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
                  int itemId = MyClass.this.lv.pointToPosition(
                          (int) e1.getX(), (int) e1.getY());
  
                  Log.v("item id", String.valueOf(itemId));
                  View v = MyClass.this.adapter
                          .getViewOnScreen(itemId);
                  Button delete = (Button) v.findViewById(R.id.button_delete);
  
                  delete.setVisibility(View.VISIBLE);
                  //MyClass.this.adapter.notifyDataSetChanged();
  
  
              }
  
          } catch (Exception e) {
              // nothing
          }
          return false;
      }
  }
  </code></pre>
  
  <p>My list adapter code is the same as the referenced question.</p>
  
  <p>Edit: I tried using getChildAt() on the listview to get the row's view, and this works when there is one screen or less of items, but when there's more than the wrong view is returned and therefore the wrong delete button becomes visible.</p>
  
  <p>Edit 2: I used the answer on the question <a href="https://stackoverflow.com/a/2140831/211457">here</a> to get it to work: </p>