什么是方法adapter.notifyDataSetInvalidated()完成? 目前它没有文档。
What does the method adapter.notifyDataSetInvalidated() accomplish? There is no documentation on it.
我想重新加载ListView和notifyDataSetChanged或notifyDataSetInvalidated似乎并没有完成任何事情。
I am trying to reload a ListView and notifyDataSetChanged or notifyDataSetInvalidated don't seem to accomplish anything.
这取决于适配器实现......如果你把源$ C $一脸c您将看到:
It depends on the adapter implementation... if you take a look of the source code you will see that:
notifyDataSetInvalidated()
调用 notifyInvalidated()
的 DataSetObservable
类(see这里)
之后, notifyInvalidated()
调用 onInvalidated()
方法为每个 DataSetObserver
(see这里)。
接下来是有趣的部分: onInvalidated()
does没有做任何事情 ...
notifyDataSetInvalidated()
calls the notifyInvalidated()
of the DataSetObservable
class (see here)
Then, notifyInvalidated()
calls the onInvalidated()
method for each DataSetObserver
(see here).
Then comes the funny part: onInvalidated()
does not do anything...
这是它的实现:
public void onInvalidated() {
// Do nothing
}
DataSetObserver
是一个抽象类,所以它的子类来决定该怎么办了 onInvalidated()
DataSetObserver
is an abstract class, so it's up to the subclass to decide what to do on onInvalidated()
.