Android notifyDataSetChanged for ExpandableListView not working

In my application, I work with ExpandableListView . I am using an adapter that extends BaseExpandableListAdapter . I want to update ExpandableListView .

My ExpandableListView consists of items with a delete button that links to the database. If I press the delete button, the item will be deleted permanently with db. But listview not refreshing at the same time. If I start this activity again, it is refreshing, but not at the same time. I use

 mAdapter.notifyDataSetChanged(); 

but it does not work as I want. Why?

+6
source share
5 answers

I just called super on the next overridden BaseExpandableListAdapter method, and notifyDataSetChanged () has been working ever since.

  @Override public void registerDataSetObserver(DataSetObserver observer) { super.registerDataSetObserver(observer); } 
+8
source

you can try additionally calling invalidateViews () on the ExpandableListView when updating.

+4
source

You need to wait until the entire drawing is drawn, and then you can call notifyDataSetChanged ()

"Viewer tree observer is used to register listeners who can be notified of global changes in the view tree. Such global events include, but are not limited to, the whole tree layout, the start of the drawing passage, touch mode change .... ViewTreeObserver never must be created by applications because it is provided by the hierarchy of views For more information, see getViewTreeObserver ().

http://developer.android.com/reference/android/view/ViewTreeObserver.html

  final View v = convertView; ViewTreeObserver vto = convertView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { v.getViewTreeObserver().removeOnGlobalLayoutListener(this); notifyDataSetChanged(); }}); 
0
source

If you are using Big Nerd Ranch extensible lists, note that the traditional notifyDataSetChanged() of RecyclerView.adapter does not work.

Instead, the extensible RecyclerView provides a set of notifications that can inform the adapter of changes to the ParentListItems list.

 // Parent Changes notifyParentItemInserted(int parentPosition) notifyParentItemRemoved(int parentPosition) notifyParentItemChanged(int parentPosition) notifyParentItemRangeInserted(int parentPositionStart, int itemCount) // Child Changes notifyChildItemInserted(int parentPosition, int childPosition) notifyChildItemRemoved(int parentPosition, int childPosition) notifyChildItemChanged(int parentPosition, int childPosition) 

For more information, visit https://bignerdranch.imtqy.com/expandable-recycler-view/

0
source

In your custom adapter, override the BaseExpandableListAdapter methods that you want to call (BaseExpandableListAdapter is an abstract class), including notifyDataSetChanged (). To call notifyDataSetChanged () from your adapter instance, in your mAdapter add:

 @Override public void notifyDataSetChanged() { super.notifyDataSetChanged(); } 

to your adapter class, then:

 mAdapter.notifyDataSetChanged(); 

should work fine.

0
source

Source: https://habr.com/ru/post/899589/


All Articles