3

I'm using Chris Banes's (older) pulltorefresh library. I have it working except when the user doesn't pull all the way down (not far enough to refresh) the View doesn't scroll back up. It scrolls if the user pulls all the way down. Anyone have any idea what I'm doing wrong?

ANSWER: I finally figured this out. You have to add a line in the PullToRefreshBase.java file. In the OnTouchEvent method in the Switch Statement add setheaderScroll(0).

...
case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            setHeaderScroll(0); //ADD THIS
            if (mIsBeingDragged) {
                mIsBeingDragged = false;
...
smoreilly
  • 55
  • 5

2 Answers2

0

Disable the pull to bottom to refresh function, add a loadding footer to the PullToRefreshListView and set OnScrollListener on the ListView, if the ListView is scroll to bottom, show the loading footer, and execute the AsyncTask to load more data

pullToRefreshListView.getRefreshableView().setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (++firstVisibleItem + visibleItemCount > totalItemCount) {
                    // show loading footer, execute AsyncTask
                }
            }
        });
Wesley
  • 4,084
  • 6
  • 37
  • 60
0

You should be using SwipeRefreshLayout, newly released in the latest support library from Google. Since Chris Banes's it deprecated and will no longer by maintained by him.

Also this library will give you the desired effect of bouncing back to it´s original position if the user doesn't pull it all the way down.

Here you have a example of how to use it.

XML view

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="@string/hello_world"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"/>
    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

Java code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
        android.R.color.holo_green_light, 
        android.R.color.holo_orange_light, 
        android.R.color.holo_red_light);
}

@Override public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
            swipeLayout.setRefreshing(false);
        }
    }, 5000);
}
reixa
  • 6,903
  • 6
  • 49
  • 68