A
A
Alexey Grichenko2011-08-09 19:19:46
Android
Alexey Grichenko, 2011-08-09 19:19:46

How to track the readiness of ListView in android?

It seems like a simple problem, but I can not find the right answer yet.
There is a ListView with an adapter to the database. At some point, this adapter starts a new query and populates the list with items. After this is done, I need to rewind the list to a known position. The problem is that while the list is empty, rewind does not work. And I did not find any events like "list is full". So far I've made a small hack: before updating the adapter, I set the "need to rewind" flag, and in setViewValue I check it and if necessary I call setSelection, I reset the flag. It seems to work, but somehow it looks very sloppy.
We need the help of the audience: how best to implement this business?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2011-08-10
@WNeZRoS

ArrayAdapter has a setNotifyOnChange(notifyDataSetChanged) method, check it out, it might help.

A
Alexey Grichenko, 2011-08-10
@Kalobok

Yes, I already thought about it. Here's the ambush: most likely, the ListView itself is updated on the same event. And I'm not sure if a certain order in which handlers are called is guaranteed. I'm afraid to get subtle glitches when sometimes the ListView fires first and everything works, and sometimes my handler, and the ListView is not yet filled at that time.
But it's probably worth a try.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question