ExpandableListView 的 android notificationDataSetChanged 不起作用
在我的应用程序中,我正在使用 ExpandableListView
。我正在使用扩展BaseExpandableListAdapter
的适配器。我想刷新 ExpandableListView
。
我的 ExpandableListView
由带有与数据库链接的删除按钮的项目组成。 如果我按下删除按钮,该项目将从数据库中永久删除。但是listview
并没有同时刷新。如果我再次运行该活动,它会令人耳目一新,但不是同时进行。 我正在使用
mAdapter.notifyDataSetChanged();
,但它没有按我想要的方式工作。 为什么?
In my app I am working with ExpandableListView
. I am using adapter which extends BaseExpandableListAdapter
. I want to refresh the ExpandableListView
.
My ExpandableListView
consists of items with delete button which links with database.
If I'll press the delete button that item is permanently deleted from db. But the listview
is not refreshing at the same time. If I again run that activity its refreshing but not at same time.
I am using
mAdapter.notifyDataSetChanged();
but its not working as I want.
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚在 BaseExpandableListAdapter 的以下重写方法上调用了 super,从那时起,notifyDataSetChanged() 就起作用了。
I just called super on the following overridden method of the BaseExpandableListAdapter and since then the notifyDataSetChanged() works.
您可以尝试在刷新时在 ExpandableListView 上另外调用 invalidateViews() 。
you can try to additionally call invalidateViews() on your ExpandableListView when refreshing.
你必须等到整个viewtree都被绘制出来,然后你可以调用notifyDataSetChanged()
“视图树观察者用于注册监听器,这些监听器可以通知视图树中的全局变化。这样的全局事件包括,但是不限于,整个树的布局,绘图过程的开始,触摸模式更改...... ViewTreeObserver 不应该由应用程序实例化,因为它是由视图层次结构提供的,请参阅 getViewTreeObserver() 了解更多信息。信息。”
http://developer.android.com/reference/ android/view/ViewTreeObserver.html
You have to wait until the whole viewtree has been drawn and then you can call notifyDataSetChanged()
"A view tree observer is used to register listeners that can be notified of global changes in the view tree. Such global events include, but are not limited to, layout of the whole tree, beginning of the drawing pass, touch mode change.... A ViewTreeObserver should never be instantiated by applications as it is provided by the views hierarchy. Refer to getViewTreeObserver() for more information."
http://developer.android.com/reference/android/view/ViewTreeObserver.html
如果您使用 Big Nerd Ranch 的 Expandable 列表,请注意
RecyclerView.adapter
的传统notifyDataSetChanged()
不起作用。相反,Expandable RecyclerView 提供了一组通知方法,能够通知适配器 ParentListItems 列表的更改。
有关更多详细信息,请访问 https://bignerdranch.github.io/expandable-recycler-view/
If you are using Expandable lists of Big Nerd Ranch, please note that traditional
notifyDataSetChanged()
ofRecyclerView.adapter
is not working.Instead Expandable RecyclerView provides a set of notify methods with the ability to inform the adapter of changes to the list of ParentListItems.
For additional specifics visit https://bignerdranch.github.io/expandable-recycler-view/