How to refresh expandablelistview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.