Android: listview: convertview. settag () to set data

Source: Internet
Author: User
Void Android. View. View. settag (Object Tag) Public void Settag (Object Tag) Since: API Level 1

Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. tags can also be used to store data within a view without resorting to another data structure.

Parameters An object to tag the view


Also see

    • Gettag ()
    • Settag (INT,
      Object)
     Public View getview ( Int  Position, view convertview, viewgroup parent ){  Final   Int Cc = Position; viewholder holder = Null  ;  If (Convertview = Null  ) {Holder =New  Viewholder (); convertview = Minflater. Inflate (R. layout. itemrow, Null  ); Holder. tagcolor = (Imageview) convertview. findviewbyid (R. Id. itemrowiamge); Holder. itemname = (Textview) convertview. findviewbyid (R. Id. itemrowtext); Holder. CB = (Checkbox) convertview. findviewbyid (R. Id. itemrowcb); convertview. settag (holder );}  Else  {Holder =(Viewholder) convertview. gettag ();}  //  Obtain the data filled in viewholder. Holder. tagcolor. setbackgroundresource (integer) itemlist. Get (position). Get ("IMG" ); Holder. itemname. settext (string) itemlist. Get (position). Get ( "Itemname" ); Holder. CKD = (String) itemlist. Get (position). Get ("checked" );  //  The checkbox key listening function in a single project Holder. CB. setonclicklistener ( New View. onclicklistener (){  Public   Void  Onclick (view v) {SETC (CC );  //  Call the function to change the status after being pressed.  }});  If (Holder. CKD. Equals ("T" ) Holder. CB. setchecked (  True  );  Else  Holder. CB. setchecked ( False  );  Return  Convertview ;} 

Set a holder class

 Import  Android. widget. checkbox;  Import  Android. widget. imageview;  Import  Android. widget. textview;  //  The viewholder class is used to store the data required by each project.  Public   Class  Viewholder { Public Imageview tagcolor; //  Images in a single project      Public Textview itemname; //  Text in a single project      Public Checkbox CB; //  Checkbox in a single project      Public String CKD; //  String variable used to identify the checkbox status in a single project }

You can.

Related Article

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.