views:

40

answers:

2

I've been messing with some layouts for my ListActivity's ListView and found a problem:

When I click a list item it starts a new Activity. Unfortunately, when I click the back button to go back to my ListActivity, the scrollbar of the ListView is all the way at the top.

It used to be that, when I clicked the back button, the user would be scrolled to the same place in the list as they were before they selected the list item to launch a new screen.

I'm pretty sure I've removed all of the code I've changed, but the problem is still occurring. Any ideas?

A: 

If you're hitting on create in your code your list most likely is recreated and therefore position is not saved. Try to rotate device while in the ListActivity ( scroll to the middle and rotate ) and see if you see the problem . I'd cache the postion of the list and scroll List to it. Example of such things : http://developer.android.com/resources/tutorials/notepad/notepad-ex3.html

Alex Volovoy
I'm only hitting onCreate once. When I hit back on the second Activity, since the previous Activity (with the ListView) wasn't destroyed, it's brought to the top of the stack. Previously, the scroll of the ListView would be what I left it at. Now it's at the top :\ I shouldn't have to cache off the position because Android is supposed to handle this for me. I've obviously done something to screw it up, but I can't figure out what :\
Andrew
It would be extremely hard to tell without the code.
Alex Volovoy
A: 

I figured out why this is happening

    @Override public void onStop() {
    super.onStop();
    if (mCursor != null) {
        mCursor.close();
        mCursor = null;
    }
    mAdapter.changeCursor(null);
}

I was told this is something I'm "supposed" to do. I think I can understand why. However, it causes the undesirable behavior I'm seeing here.

Andrew