Android_Paradise
Android_Paradise

Reputation: 325

Issue while scroll List view with Pull to Refresh

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();
}

Upvotes: 6

Views: 3863

Answers (1)

user2776223
user2776223

Reputation:

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..

Upvotes: 17

Related Questions