Really basic question about ListView updates

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Really basic question about ListView updates

Postby Sweevo » Fri Nov 14, 2008 4:33 am

Suppose I want to write something like an IM client - I'd use a ListActivity / ListView and some ArrayAdapter to render the list of contacts.

What happens when a contact goes online/offline? how do you tell the ListView to update that row? (changing the status image, the name and the rest stay the same).

I know the easy way is just to call setListAdapter again, but that would redraw the entire list, moving the scrollbar to the top, which can be very annoying for the poor user. I hope there's a way to update just the one contact, or at least get the scrollbar position and set it again.
Sweevo
Developer
Developer
 
Posts: 35
Joined: Thu Oct 16, 2008 9:27 am

Top

Postby rmanromga » Fri Nov 14, 2008 5:22 am

Good question, I will need to do that later also in my project... ListView has a functioin called

getLastVisiblePosition()

which according to the API Returns the position within the adapter's data set for the last item displayed on screen.

Thats where I would start if you have no option but call setListAdapter() again, then this would be an option to "bookmark" where the adapter was.... let us know if your fare well ;-)

--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Postby Sweevo » Fri Nov 14, 2008 5:58 am

I don't see, though, where I could use the value returned by getLastVisiblePosition().
Sweevo
Developer
Developer
 
Posts: 35
Joined: Thu Oct 16, 2008 9:27 am

Postby rmanromga » Fri Nov 14, 2008 6:14 am

I was thinking that if say there is a contact in position 20 on the list that goes off line, every time a person goes off line, you could save the value of the position returned by getLastVisiblePosition() then re-set the adapter, then after the adpter has been set, you could then jump back to the position you had saved using ListView.setSelection() or ListView.setSelectionFromTop() then that would get you back to position 21 (or 19 if you play around with the variable) then your user will not have to scroll down from the top again.... theoretically it makes sense to me, but I don't know if it will work...
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Postby Sweevo » Fri Nov 14, 2008 6:21 am

This would still jump around - it's not likely that the top of the list view is exactly aligning with the top of an item.

It's certainly better than nothing, but I don't think it's the "proper" way to go about it.
Sweevo
Developer
Developer
 
Posts: 35
Joined: Thu Oct 16, 2008 9:27 am

Postby rmanromga » Fri Nov 14, 2008 6:33 am

I know... I feel your pain....my suggestion really feels like a bad hack :-).... some time next week I will be working on a view that needs to do the same thing.... If I find anything, I will update the thread...

cheers
--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests