Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old March 8th, 2010, 10:10 AM   #1 (permalink)
New Member
 
Join Date: Jan 2010
Posts: 11
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remember listview position and selection

Hi there
I have a problem with a listview i'm using. I load the data in the listview from a cursorAdapter and when i select an item an onItemClickListener launches the corresponging activity. Now when i press the back button i would like
the listview to remember the previous position and selection but it just loads the list from the start, none of these is remembered.Can anyone help me with an example? Thank you

kaliki is offline  
Reply With Quote
Sponsors
Old March 8th, 2010, 11:26 AM   #2 (permalink)
New Member
 
Zero's Avatar
 
Join Date: Oct 2009
Posts: 11
 
Device(s):
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You need to save the selection position before refreshing your adapter. I use this in onRestart():

Code:
        int selection = mListView.getSelectedItemPosition();
        mAdapter.refresh(); //reload the data, refresh is my own method, you can 
//use notifyDataSetChanged()/Invalidated()
        mListView.setSelection(selection);
Zero is offline  
Last edited by Zero; March 8th, 2010 at 11:27 AM.
Reply With Quote
Old March 9th, 2010, 08:40 AM   #3 (permalink)
New Member
 
Join Date: Jan 2010
Posts: 11
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks that worked great
kaliki is offline  
Reply With Quote
Old September 7th, 2011, 03:30 AM   #4 (permalink)
New Member
 
Join Date: Jun 2011
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Should i pass the selected item position to the next screen?
navsoftdev87 is offline  
Reply With Quote
Old September 7th, 2011, 07:38 PM   #5 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 6,032
 
Device(s): GalaxyNexus(LTE), NexusOne, OG Droid, GalaxyTab 10.1(LTE), Eris, Logitech Revue (fishtank)
Thanks: 2,326
Thanked 2,079 Times in 847 Posts
Default

If you need it on the next screen Otherwise it's better to save in the instance state.


You guys may want to look at Loader too if you are using cursor/simplecursor adapters

It's new in Android 3.0 but they added it to the compatibility package so you can use it all the way back to 1.6

hth
alostpacket is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
GPS Position on photos? cooverdj Android Applications 3 June 28th, 2011 05:05 PM
cursor not returning correct row position in ListView motoko Application Development 0 September 14th, 2010 11:58 AM
Accelerometer out of position Aurvan Android Lounge 6 January 19th, 2010 10:27 PM
Manually set position Formsvacka HTC Hero 0 January 1st, 2010 10:34 AM
WEP password position seucuca T-Mobile G1 0 October 23rd, 2009 06:56 PM



All times are GMT -5. The time now is 09:03 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo


SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.