Is there a way to call notifyDataSetChanged() from the main activity for a custom adapter of an item inside another custom adapter?

☆樱花仙子☆ 提交于 2019-12-04 06:16:12

问题


I've being trying to solve this problem but I couldn't figure it out yet. In my layout have a listview with its custom adapter. Inside each view I have many objects stored in a static class called ViewHolder. One is a gallery with another custom adapter.

My problem is that after I get an onActivityResult on my Activity. I need to send a notifyDataSetChanged() to my gallery adapter. If I do:

((BaseAdapter)list.getAdapter()).notifyDataSetChanged();

All the items inside the adapter are refreshed except the ones that have their own custom adapter.

Now I thought maybe I thought maybe there is a way to override onNotifyDataSetChanged() or something like that to send the notification from within my ListAdapter once I notify it. But I couldn't find something like this, is there a way to do this?

I've also noticed that if I try to do:

((BaseAdapter)ListAdapter.ViewHolder.this.gallery.getAdapter()).notifyDataSetChanged();

It sais: "No enclosing instance of ListAdapter.ViewHolder is accesible in scope" Is there a way to make it accessible?

Or another way to accomplish what I'm trying to do?

Thanks in advance


回答1:


I feel ashamed... It seemed that I forgot to renew a few variables for it to work right...

So the conclusion is the adapter inside the adapter gets updated if you call:

.notifyDataSetChanged();

You just have to do it right



来源:https://stackoverflow.com/questions/4754208/is-there-a-way-to-call-notifydatasetchanged-from-the-main-activity-for-a-custo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!