0

I faced with problem, when I can not detect action down event.I want implement pull-to-refresh to the listview as in the link: http://www.javacodegeeks.com/2013/06/android-listview-pull-to-refresh.html.

@Override
public boolean onTouchEvent(MotionEvent event) {
    //System.out.println("First ["+this.getFirstVisiblePosition()+"]");

    float y = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE: {
            Log.d(LOG_TAG, "MOVE");
            if ( ( y - startY) > THRESHOLD && STATE_REFRESH_ENABLED && !STATE_REFRESHING ) {

            }
        }
        break;
        case MotionEvent.ACTION_DOWN: {
            Log.d(LOG_TAG, "DOWN");
            startY = y;
            STATE_REFRESH_ENABLED = getFirstVisiblePosition() == 0; // We are on the first element so we can enable refresh
        }
        case MotionEvent.ACTION_UP: {
            Log.d(LOG_TAG, "UP");
            STATE_REFRESHING = false;
        }

    }
    return super.onTouchEvent(event);
}

According to log down acion is not detected. Thanks in advance.

ema
  • 891
  • 11
  • 21
  • What type of class is this in? An Activity? A custom View? Have you check to see if `onTouchEvent()` is getting called at all? Also, have you considered using the new [`SwipeRefreshLayout` provided by the support library](http://stackoverflow.com/questions/22738522/simple-example-on-how-to-use-swiperefreshlayout-with-listview)? – Bryan Herbst May 29 '14 at 19:58
  • May seem like a dumb question, but you are sure you have set your listener? – zgc7009 May 29 '14 at 20:17
  • Class is ListView. I tried to set custom OnTouchListener with that code. Move and Up are catched. – ema May 29 '14 at 20:34
  • In SwipeRefreshLayout you can't define custom threshold – ema May 29 '14 at 21:02

0 Answers0