5

I am using Staggeredgridview in my Project.

I've downloaded StaggeredGridView library and demo from here: https://github.com/maurycyw/StaggeredGridViewDemo https://github.com/maurycyw/StaggeredGridView

I need to PullToRefresh for that entire gridview

Thanks all

rajeswari ratala
  • 650
  • 7
  • 14
Gioan Doan
  • 112
  • 8

2 Answers2

3

Just Added Support for StaggeredGridView in Chris Banes Android-PullToRefresh. Also support Actionbar-PullToRefresh for ActionBarSherlock.

Mihir
  • 2,064
  • 2
  • 21
  • 28
  • That PullToRefresh library has been deprecated... Any solution for Chris Banes' new version? – Mark Buikema Nov 13 '13 at 21:37
  • Post the Link of the new version I will look in to it. – Mihir Nov 14 '13 at 06:38
  • https://github.com/chrisbanes/ActionBar-PullToRefresh I managed to make it work when only the first list item is still visible, but that still doesn't give the best UX, when you scroll down and the first item is still visible, you can't scroll up again because it will refresh. – Mark Buikema Nov 14 '13 at 10:26
0

Enclose the gridview in SwipeRefreshLyout.

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

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

Add onScroll listener for the gridview in onViewCreated. Set conditions when the refresh is enabled.

    swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeLayout);
    swipeRefreshLayout.setColorSchemeResources(R.color.theme_color);
    swipeRefreshLayout.setOnRefreshListener(this);
    gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int dist = gridView.getDistanceToTop();

            if (dist == 0)
                swipeRefreshLayout.setEnabled(true);
            else {
                swipeRefreshLayout.setEnabled(false);
            }

        }
    });

Then add a onRefresh function.

     @Override
    public void onRefresh() {
      if (!swipeRefreshLayout.isRefreshing()) {
          swipeRefreshLayout.setRefreshing(true);
      }
      //add functionality then set refresh to false
      swipeRefreshLayout.setRefreshing(false);
    }
rajeswari ratala
  • 650
  • 7
  • 14