Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If list position is retained on rotation header get unstuck #24

Closed
akshaydashrath opened this issue Sep 17, 2012 · 18 comments
Closed

If list position is retained on rotation header get unstuck #24

akshaydashrath opened this issue Sep 17, 2012 · 18 comments
Labels

Comments

@akshaydashrath
Copy link

If I store the position of the listview in saved instance state and then rotate and set selection of the listview the header is back to the top of the list and scrolls with the list, the issue is fixed if I scroll back upt to the top of the list and then rotate.

@rciovati
Copy link
Contributor

I'm able to save the list position and restore it after screen rotation, so it works fine for me.
Can you provide some demo code?

@akshaydashrath
Copy link
Author

Sure, I save list position like this:

@OverRide
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
this.firstVisible = firstVisibleItem;
}

@OverRide
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_LIST_POSITION, firstVisible);
}

@OverRide
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setOnScrollListener(this);
if (savedInstanceState != null) {
firstVisible = savedInstanceState.getInt(KEY_LIST_POSITION);
}
}

private void renewListPosition() {
getListView().setSelection(firstVisible);
}

@Override
public void setListAdapter(ListAdapter adapter) {
    super.setListAdapter(adapter);
    if (adapter != null) {
        renewListPosition();
    }
}

@rciovati
Copy link
Contributor

I use getListView().getFirstVisiblePosition() for save and getListView().setSelectionFromTop() for restore and it works.

@akshaydashrath
Copy link
Author

The problem is do that in onSavedInstanceState when using fragments using the compatibility library is the onSavedInstanceState is called after onPause which gives you a content view not created error

@emilsjolander
Copy link
Owner

on what version of android are you seeing this?

@akshaydashrath
Copy link
Author

4.1.1

@emilsjolander
Copy link
Owner

I just want to clarify the issue, when setting the selection after rotation, the headers are no longer sticky?

@akshaydashrath
Copy link
Author

Yes that is correct, Ive moved to say position 15 and the header is now back to the top of the list, adding some logs I notice that the header on rotation is now null

@emilsjolander
Copy link
Owner

And you have the list inside a support fragment? Anything more i need to know? Setting up a test project now to try to replicate this

@akshaydashrath
Copy link
Author

Nope thats about it.

@emilsjolander
Copy link
Owner

ok, so i tried but it seems to be working just fine. Could you maybe zip up a test project where you are seeing this problem and send it to me so i could take a look?

@akshaydashrath
Copy link
Author

Another thing is I'm using a cursor loader to set the adapter, I'll send some code over to you.

@akshaydashrath
Copy link
Author

Its very strange, I modified the example app to use the same code I'm using in the project, but the issue cant be reproduced, I'm going to test it a bit more, and if I cant reproduce it Ill close the issue.

@emilsjolander
Copy link
Owner

sounds good :)

@akshaydashrath
Copy link
Author

If a list has only a single header on the page this issue seems to occur, if theres more than a single header its fine

@emilsjolander
Copy link
Owner

I just tried this with only a single header and still not seeing it. I think i will need a zipped test project where this issue is present.

@androidmoney
Copy link
Contributor

Well, I cannot provide one as it doesn't happen on my phone. But it's easy to see by looking at your code that if you get 2 pushes without a pull, you will pull the wrong item of the cache. It's been a long time, but your code seems to assume that you will get a push and a pull paired.

@emilsjolander
Copy link
Owner

Many things have been remade since this issue was posted and i have never been able to reproduce it so i am closing it. Please submit another issue if you still see this with the newest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants