Android control-twolinelistitem

Source: Internet
Author: User

Twolinelistitem inherits Android. widget. relativelayout. It is composed of two subviews and is usually used in listview.

It requires two textviews (the id value is text1 and text2), and an optional third view (the id value is selectedicon)

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <twolinelistitem xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"> </P> <p> <imageview Android: Id = "@ + ID/icon" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: src = "@ Android: drawable/presence_offline "/> </P> <p> <textview Android: Id =" @ Android: ID/text1 "<br/> Android: layout_margintop = "1dip" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_torightof = "@ ID/icon" <br/> Android: textsize = "15dip" <br/> Android: text = "ssssssssssssssssssssssssssss" <br/> Android: textstyle = "bold"/> </P> <p> <textview Android: Id = "@ Android: ID/text2" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_below = "@ Android: ID/text1" <br/> Android: layout_alignleft = "@ Android: ID/text1" <br/> Android: paddingbottom = "4dip" <br/> Android: includefontpadding = "false" <br/> Android: textsize = "15dip" <br/> Android: text = "" <br/> Android: textstyle = "normal"/> </P> <p> <imageview Android: id = "@ Android: ID/selectedicon" <br/> Android: layout_margintop = "9dip" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_alignparentright = "true" <br/> Android: layout_marginright = "7dip" <br/> Android: src = "@ Android: drawable/sym_action_call "/> <br/> </twolinelistitem>
Effect:


Source code:

Import Java. util. arraylist; <br/> Import Java. util. list; </P> <p> Import android. app. listactivity; <br/> Import android. OS. bundle; </P> <p> public class twolineitemactivity extends listactivity {<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setlistadapter (New contactarrayadapter (this, R. layout. main, getcontacts (); <br/>}</P> <p> private list <contacts> getcontacts () {<br/> List <contacts> contacts = new arraylist <contacts> (); <br/> contacts C; <br/> C = new contacts (); <br/> C. setname ("Shriram"); <br/> C. setphone ("123456"); </P> <p> contacts. add (c); </P> <p> C = new contacts (); <br/> C. setname ("John"); <br/> C. setphone ("456789"); <br/> contacts. add (c); <br/> return contacts; </P> <p >}< br/>}
</P> <p> Import Java. util. list; </P> <p> Import android. content. context; <br/> Import android. view. layoutinflater; <br/> Import android. view. view; <br/> Import android. view. viewgroup; <br/> Import android. widget. arrayadapter; <br/> Import android. widget. twolinelistitem; </P> <p> public class contactarrayadapter extends arrayadapter <contacts >{</P> <p> private int resourceid; </P> <p> Public contactarrayadapter (Conte XT context, int textviewresourceid, list <contacts> Object) {<br/> super (context, textviewresourceid, object); <br/> resourceid = textviewresourceid; <br/> // todo auto-generated constructor stub <br/>}< br/> @ override <br/> Public View getview (INT position, view convertview, viewgroup parent) {<br/> contacts = getitem (position); <br/> If (contacts = NULL) {<br/> return NULL; <br/>}< br/> // get a layoutin Flater instance <br/> layoutinflater Inflater = (layoutinflater) getcontext (). getsystemservice (context. layout_inflater_service); <br/> twolinelistitem view; <br/> If (convertview = NULL) {<br/> View = (twolinelistitem) Inflater. inflate (resourceid, parent, false); // view generated by XML <br/>}else {<br/> View = (twolinelistitem) convertview; <br/>}< br/> If (view. gettext1 ()! = NULL) {<br/> View. gettext1 (). settext (contacts. getname (); <br/>}< br/> If (view. gettext2 ()! = NULL) {<br/> View. gettext2 (). settext (contacts. getphone (); <br/>}< br/> return view; </P> <p >}< br/>



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.