We have an app with a ListActivity and an edit view. Tap on an item in
the ListActivity, see the edit view of that item, hit the Back key,
see the list view. All very ordinary stuff.

But, in this app, the ListActivity does not retain its postion during
that sequence. After hitting Back, the list is always scrolled to the
very top.

Experimenting on the Notepad sample reveals that adding a header view
to the list causes the same problem there. With the header view, the
list is always scrolled to the top after hitting Back on the note
editor. Without the header view, the list retains its scroll position.

Is that behaviour by design, or a consequence of something we are
doing wrong  ? I can't find any way to turn it off, but it doesn't
seem to be obviously desirable.

Thanks,
Richard

Oh - here's the amended Notepad OnCreate:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

        // If no data was given in the intent (because we were started
        // as a MAIN activity), then use our default content provider.
        Intent intent = getIntent();
        if (intent.getData() == null) {
            intent.setData(Notes.CONTENT_URI);
        }

        // Inform the list we provide context menus for items
        getListView().setOnCreateContextMenuListener(this);

        // Perform a managed query. The Activity will handle closing
and requerying the cursor
        // when needed.
        Cursor cursor = managedQuery(getIntent().getData(),
PROJECTION, null, null,
                Notes.DEFAULT_SORT_ORDER);



//  >>>>>>>>>>>>>>>>>>>>>>>
//  These two lines stop the list restoring its position
correctly

        View newNoteView =
LayoutInflater.from(this).inflate(R.layout.noteslist_item, null);
        getListView().addHeaderView( newNoteView );

// >>>>>>>>>>>>>>>>>>>>>>>>


        // Used to map notes entries from the database to views
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.noteslist_item, cursor,
                new String[] { Notes.TITLE }, new int[]
{ android.R.id.text1 });
        setListAdapter(adapter);

     }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to