开发者

Google I/O 2010 - The world of ListView notifyDataSetChanged()

开发者 https://www.devze.com 2023-04-12 04:01 出处:网络
sorry for stupid question. But really interesting and incomprehensible. In this session discussed about notifyDataSetChanged() method.

sorry for stupid question. But really interesting and incomprehensible. In this session discussed about notifyDataSetChanged() method.

From documentation for this method - "called when the data set being observed has changed, and which when read contains the new state of the data". My English bad and 开发者_Python百科I do not understand all. But I right if guess that method called when I need refresh ListView with new data set?

If I'm right then I'm confused. In the past and my first program I played with contacts api of android. And run some processing in an asynctask. At this time appeared dialog with progress bar and in the background, you could see how the state of ListView changed in real time. Data for ListView row changed via BindView.

Why? So I'm in something wrong. Explain please.


As i read it, BindView is only used with cursors, which are a specific type of a data set basically. You can have alternative data sets, there is for example an ArrayListAdapter in the API which uses an ArrayList as its dataset. In case that data set changes, notifyDataSetChanged() will have to be called to notify the list view that its bounds will have to be recalculated and its views have to be redrawn (and probably some more).

If you decide to write your own and create the possibility to modify the data shown in the list view through an adapter (one could imagine adding method like addObject(SomeObject o) in your home made adapter for example), then you'd call notifyDataSetChanged() in that method.

Similarly if you have a deleteObject(SomeObject x), if the remaining data set is larger than zero you'd call notifyDataSetChanged() or when the remaining data set is empty you'd call notifyDataSetInvalidated() which in turn will to some extra stuff like setting the so called empty view in the list if you have one specified.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号