3

I am using PullToRefresh in my android app. It is working fine so far.

Issue I am facing is when I download new x rows on "Release to refresh" from TOP new rows pushes existing rows and starts from 0 position it is annoying for the user. What I want is, after downloading new set of rows list should remain there and let user fling down to view new set of rows.

any idea how can I achieve this?

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
user2095470
  • 356
  • 1
  • 6
  • 23

1 Answers1

11

This is what i use

//Get old position before updating adapter
final int old_pos = mListView.getRefreshableView().getFirstVisiblePosition()+1;
//Set Adapter
mListView.setAdapter(mListAdapter);

//Set the list to old postion
//mListView.getRefreshableView().setSelection(old_pos);
mListAdapter.notifyDataSetChanged();
mListView.onRefreshComplete();

mListView.post(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            mListView.getRefreshableView().setSelection(old_pos);
        }
    });

also check this: Maintain/Save/Restore scroll position when returning to a ListView

Community
  • 1
  • 1
Naveen
  • 1,703
  • 13
  • 22
  • both getFirstVisiblePosition() and setSelection() are not available if we use PullToRefreshListView ListView. – user2095470 Mar 15 '13 at 07:26
  • Also, as per my understanding if I am pulling data from TOP then fristVisiblePosition() should always be zero isn't it right? – user2095470 Mar 15 '13 at 07:30
  • I have updated my answer, check it I have added getRefreshableView() it will have both methods and also if you are pulling from top you should add the rows on top and same goes for pulling from bottom. yes the TOP will be zero when pulled from top – Naveen Mar 15 '13 at 07:43
  • Ok, got the refreshable instance from getRefreshableView(). Tried what you suggested but didn't work. In fact I saw [code here] (https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/PullToRefreshListView.java) and it handles issue neatly. But it is not working for me. – user2095470 Mar 15 '13 at 07:46
  • It is not neat design as you are setting up values is new thread. – user2095470 Mar 15 '13 at 08:06
  • I know this doesn't look good but the old code was not working for you so I was trying something different. You should try the old edited answer and output old_pos to see what is not working. – Naveen Mar 15 '13 at 08:12