Search code examples
androidpull-to-refresh

Pull-To-Refresh: ListView breaks while animating


I am using this PullToRefresh Code:

https://github.com/erikwt/PullToRefresh-ListView

XML Code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_listview_grey" >

    <eu.erikw.PullToRefreshListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="6dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="6dp"
        android:divider="@color/bg_listview_grey"
        android:dividerHeight="6dp"
        android:drawSelectorOnTop="true"
        android:scrollbars="none" />

</RelativeLayout>

Activity Code related to the ListView:

listView = (PullToRefreshListView) view
        .findViewById(R.id.feedListView);
footerView = inflater.inflate(R.layout.footer, listView, false);
feedListView.addFooterView(footerView);
listAdapter = new DefaultFeedAdapter((Activity) getSherlockActivity(),
        list_items, listView);
listView.setAdapter(listAdapter);

feedListView.setOnScrollListener(new OnScrollListener() {
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    }

    public void onScroll(AbsListView view, int firstVisibleItem,
            int visibleItemCount, int totalItemCount) {

        // what is the bottom item that is visible
        int lastInScreen = firstVisibleItem + visibleItemCount;
        // is the bottom item visible & not loading more already ? Load
        // more !
        if ((lastInScreen == totalItemCount) && totalItemCount >= 3
                && !LoadingNextData && !noMoreItems) {
            lastId = listAdapter.values.get(totalItemCount - 3).id;
            LoadingNextData = true;
            new GetNewItems().execute("" + lastId);
        }
    }
});

listView.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        new RefreshList().execute("");
    }
});

private class RefreshFeed extends AsyncTask<String, Void, String> {
    //adds items at the top of the list if there are any.
    //But even without any new items ie.. without touching
    //the listView, it breaks.
}

The problem is:

enter image description here

While loading, it breaks 40% of the bottom listView and when it gets loaded it breaks some 20% of the listViewand finally shows the whole listView.

Am I missing something? Please help.

Thank You.


Solution

  • Not a solution to your problem but use this:

    https://github.com/chrisbanes/Android-PullToRefresh

    Though it says

    PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED

    It works flawlessly with smooth interface.

    Like @Udi Oshi suggested you can also go with a Gmail Like pull to refresh:

    https://github.com/chrisbanes/ActionBar-PullToRefresh