ListView Group Displays network data

Source: Internet
Author: User

Recent projects need to use the form of grouping display data, drawing on the essence of the online predecessors, now write a summary, stay as a personal view.

    1. First, to define list<baseinfo> datas = new arraylist<baseinfo> () for populating the ListView data;

    2. In Baseinfo, you first need to define a classname to differentiate the category so that it can be displayed

    3. Before each set of data is stored, a Baseinfo object is stored in the datas with only ClassName, and then the group data is stored in the Datas

    4. Then populate the data in the form of Adapter fill data

    5. In Adapter, the corresponding layout file needs to be introduced for Baseinfo objects with only className not empty

      The above is the logical thinking of the ListView grouping

The following is a partial code for personal use:

Data processing code in activity:

                                                              JSONArray array_obj = response                                          . Getjsonarray ("obj");                                 for   (Int i = 0; i < array_obj.length ();  i++)  {                                      jsonobject obj = array_obj.getjsonobject ( i);                                      string classname = obj.getstring ("name");                                      string classid = obj.getstring ("id" );                                      Jsonarray array = obj                                              .getjsonarray ("Appproductclientdtolist");                                      if  (Array.Length ()  == 0)  {                                          // do nothing                                      } else {                                          baseinfo  base = new baseinfo ();                                          base.setclassname (ClassName);                                           base.setclassid (classId);                                          datas.add (Base);                                          for  (int j =  0; j < array.length ();  j++)  {                                               baseinfo baseinfo = new baseinfo ();                                                 //  Data Acquisition                                                baseinfo.setclassname (ClassName);                                               baseinfo.setclassid (classId);                                               Baseinfo.setscale (scale); &NBSP;&NBSP;&NBSP;&Nbsp;                                          baseinfo.setappid (appId);                                               Baseinfo.setdownloadnumber (downloadcounts);                                               Baseinfo.setversioncode (integer                                                      .parseint (VersionCode));                                               baseinfo.setsize (appsize);                                               baseinfo.setdownloadurl (Appfilepath);                                   &nbsP;          baseinfo.setpackagename (PackageName);                                               baseinfo.setname (name);                                               datas.add (Baseinfo);                                          }                                      }                                 }

Fill adapter After data is populated:

adapter = new Splitclassadapter (Getapplicationcontext (), datas);                        Adapter.notifydatasetchanged (); List_classes.setadapter (adapter);

Processing logic in Adapter:

              if  (Mdatas.get ( Position). GetName () ==null)  {                views = layoutinflater.from (Mcontext). Inflate (R.layout.activity_header, group , false);               header  = new viewholderheader ();                // ViewHolderHeader    Component initialization, if there are processing events, the corresponding implementation  .          }else{                views = layoutinflater.from (Mcontext). Inflate ( R.layout.item_class, group,false);                content = new viewholdercontent();                // The viewholdercontent  component is initialized and, if there is a handling event, it is implemented accordingly.

Also need to implement areallitemsenabled and isenabled two methods in adapter

      @Override        public boolean  Areallitemsenabled ()  {           return true;         }        @Override         public boolean isenabled (int position)  {            //  If-start, the item is not selectable              baseinfo baseinfo = mdatas.get (position);          if  (Baseinfo.getname () ==null)  {             return false;        } else{            return true;         }     } 


ListView Group Displays network data

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.