How to enable Collection notifyDataChanged?

I have a snippet where I have a ListView with BaseAdapter. Then I have a popup menu where I select an option and it adds the item to the collection. The data from the collection should appear in the list, but it doesn't. I need to add adapter.notifyDataChanged () to update the view.

The problem is that I may not have access to the adapter from different classes. How can I enable automatic updates?

PS. I tried to add data from the UI thread, but still nothing ...

                    getActivity().runOnUiThread(new Runnable() {

                        public void run() {
                            GlobalData.groupTable.put(newGroup.getId(), newGroup);

                        }
                    });

      

+3


source to share


2 answers


The problem is that I may not have access to the adapter from different classes.



Create your own callback to update the adapter. This approach is from the Developer Guide.

+3


source


This is not true. Pass the adapter as a parameter to the class that should call it. Or, you can write your own collection class that overrides the add method to call the adapter, but even then, you have to pass the adapter into a new collection class.



+2


source







All Articles