Issue while scroll List view with Pull to Refresh
Asked Answered
J

1

6

I have develop an application that have one list view and i used Pull to refresh for refresh list data while pull down so i implemented in my code perfectly but i get one issue when i am scroll up list scroll down but when i am scroll down its not scroll done because its consider pull to refresh and refresh data but i want to make it when display list index 0 then it work pull to refresh

so please help me about this

my code is

 listNotification = (ListView) rootView.findViewById(R.id.listNotification);
    listNotification.setCacheColorHint(0);


    swipeLayout = (SwipeRefreshLayout) rootView.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);

    if (Global.notifications == null) {
        swipeLayout.setRefreshing(true);
        new GetNotificationList().execute();
    }
    LoadNotificationToListView();

on refresh

 @Override
public void onRefresh() {

    new GetNotificationList().execute();
}
Jolson answered 25/8, 2014 at 11:32 Comment(0)
C
17

I think this always make confuse to developer so i get some trick for it hope you help

First override list view setOnScrollListener method for geting index of visible item

ListView.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 == 0) {
                swipeLayout.setEnabled(true);
            } else swipeLayout.setEnabled(false);
        }
    });

then set condition while firstvisible item is 0 then swipe enable otherwise disable as code you can see..

i hope this trick help you..

Chekiang answered 25/8, 2014 at 13:3 Comment(2)
how to fix it in recycler List?Eiderdown
is there an equivalent fix for pull to refresh inside a scrollviewLeonidaleonidas

© 2022 - 2024 — McMap. All rights reserved.