Preface
It is normal to use expandablelistview in a project recently, right? Because expandablelistview is really a good widget! But its refreshing problem is really disgusting! I found a lot of information on the Internet, but it is a lot of problems! Now I have developed a method, which is probably okay!
Source
Http://blog.csdn.net/arylo/article/details/8711769
Body
First, the most basic
Expandablelistview vlist = (expandablelistview) This. findviewbyid (R. id. list); elistadapter adapter = new elistadapter (getapplicationcontext (), list); // list is the data source vlist. setadapter (adapter); // The adapter will not be written. Class elistadapter extends baseexpandablelistadapter {}
In general, listview is updated using yydatasetchanged ().
Adapter. notifydatasetchanged ();
Expandablelistview is also a listview. It is estimated that this is acceptable.
Unfortunately, not listview, but expandablelistview! So the error 0. 0 is reported.
Java. Lang. classcastexception: Android. widget. expandablelistcast
I found some materials on Google and found that many of them made this mistake. The solution is quite simple!
1 class EListAdapter extends BaseExpandableListAdapter { 2 public EListAdapter(Context context, List<T> list) { 3 this.list = list; 4 this.context = context; 5 handler = new Handler(){ 6 7 @Override 8 public void handleMessage(Message msg) { 9 notifyDataSetChanged();10 super.handleMessage(msg);11 }12 };13 }14 15 public void refresh() {16 handler.sendMessage(new Message());17 }18 }
As long as we call the refresh () method, we can use yydatasetchanged.
However !! Only groupview updates are available !!
Childview is not updated! Miserable... the update is in childview !!
Continue to rely on Google Niang! Everyone provides many methods. One person said, simply add items in the list and then update them!
I tried it and it didn't have any effect .......
After checking the SDK documentation, we found that the scaling of the group may cause the running of getchildview (INT, Int, Boolean, view, viewgroup!
Therefore, the refresh childview method is very simple.
You only need to scale it once! You do not need to rewrite the adapter! Simple?
1 vList.collapseGroup(groupPosition);2 vList.expandGroup(groupPosition);
Turn: http://blog.csdn.net/arylo/article/details/8711769
How to refresh expandablelistview