johannilsson / android-pulltorefresh

DEPRECATED This project aims to provide a reusable pull to refresh widget for Android.
2.47k stars 1.03k forks source link

Can't get setSelection to work #26

Open realjax opened 13 years ago

realjax commented 13 years ago

When I try to scroll to a specific position in the list and use setSelection() nothing happens.. no error, just nothing... smoothScrollBy works fine though.

johannilsson commented 13 years ago

Thank you for the report. This is strange, it's using setSelection internally to hide the header. Will investigate.

ghost commented 13 years ago

Hm worked for me. Could you try it in the test app ?

johannilsson commented 13 years ago

I did notice that calling setSelection within onCreate had no effect even though this works fine using the standardl ListView. But this works fine in the example app;

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    setSelection(5);
}

If i remove the method onAttachedToWindow in PullToRefreshListView the call from onCreate works as expected. I can't remember why I needed to override onAttachedToWindow now though. But please test by removing that and if nothing else breaks or anyone else have any problem with removing that method I'm happy to do it.

realjax commented 13 years ago

Great! Using it in the onCreate method was also where I ran into problems. I removed the onAttachToWindow method and now everything works fine. I could see no downsides or other affects from removing the method other then the list starting out with the 'touch to refresh' message being displayed by default. A setSelection(1) in my onCreate solved this.

Many thanks for your quick response!!

johannilsson commented 13 years ago

Ah that's why we needed it. Well then I don't want to remove it until that problem is solved. If you want to play around with it you can experiment by calling setSelection(1) from other places internally in the widget.

m0rgan-plot commented 11 years ago

Hi guys. I was having the same problem, and I also managed to fix it with your solution! I simply had to remove the setSelection() call in the onAttachedToWindow() (or actually remove the onAttachedToWindow overriding).

Thanks guys.

Out of curiosity, do you remember why you called setSelection() in that method in the first place?

yochiro commented 11 years ago

I ran into the same problem, and after investigation I found out the issue, as explained below by Romain Guy https://groups.google.com/forum/?fromgroups=#!topic/android-developers/EnyldBQDUwE

I created a new method :

private void resetPosition() {
  this.post(new Runnable() {
    @Override
    public void run() {
      setSelection(1);
    }
  }
}

and replaced all references of setSelection(1) to resetPosition()

and it worked!

Arthur83 commented 8 years ago

I have the same problem, anyone here can help me?

zeeshanaslam78 commented 5 years ago

I am having the same problem in API 28 Pie. setSelection doesn't work on Pie and scrollTo works first time only but after going to next fragment and coming back to same fragment where I am using ListView, scrollTo doesn't work. So strange behavior on Pie.

johannilsson commented 5 years ago

Hi, this library is deprecated and there is no active development in it, please have a look at SwipeRefreshLayout for an alternative.

zeeshanaslam78 commented 5 years ago

Oh Sorry wrong window