Android Solution for Expandablelistview refresh problem _android

Source: Internet
Author: User

Body

The first is 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 does not write, all understand the
class Elistadapter extends Baseexpandablelistadapter {}

In general, ListView is updated with the notifydatasetchanged ()

Adapter.notifydatasetchanged ();

Expandablelistview is also ListView, it is estimated that this is possible.

Unfortunately, it's not ListView, it's expandablelistview!. So the error is 0. 0

Java.lang.ClassCastException:Android.widget.ExpandableListConnector

Looking for information in Google, found that many of them make this mistake. The solution is also quite simple!

Class Elistadapter extends Baseexpandablelistadapter {public
  elistadapter (context, list<t> List) { c2/>this.list = list;
    This.context = context;
    Handler = new Handler () {

      @Override public
      void Handlemessage (msg) {
       notifydatasetchanged ();
       Super.handlemessage (msg);}}
    ;
  
  public void Refresh () {handler.sendmessage () (
    New Message ());
  }

We can use notifydatasetchanged () as long as we call the Refresh () method.

But!! Only Groupview update!!

Childview not updated! Oh, my gosh. To be updated in the childview!!

Continue to rely on Google Niang! We all provide a lot of methods, there is a person said, directly in the list add item to be updated on it!

I tried it, no effect ...

Check the SDK documentation and find that group scaling can cause getchildview (int, int, boolean, View, ViewGroup) to run!

So the method of refreshing the Childview is very simple.

It's only a stretch once! Even adapter don't have to rewrite! Easy, huh?

Vlist.collapsegroup (groupposition);
Vlist.expandgroup (groupposition);

The above is a small series for everyone to bring Android on the Expandablelistview refresh problem solution to all the content, I hope that we support cloud Habitat Community ~

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.