Android ListView graphic mash-up

Source: Internet
Author: User

Main4.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "> <listview an Droid:id= "@+id/listview4_1_1" android:layout_width= "match_parent" android:layout_height= "Wrap_content" ></L Istview></linearlayout>


Main4_item.xml

<?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Match_parent "     android:layout_height= "wrap_content"     android:orientation= "Horizontal"      android:gravity= "Center"     ><ImageView      android:id= "@+id/imageview4_1_1"     android:layout_width= "Wrap_content"      android:layout_height= "Wrap_content"     android:src= "@drawable/ic_launcher"       /><textview     android:id= "@+id/textView4_ 1_1 "    android:layout_width=" Match_parent "    android:layout_height=" Wrap_content "    android:text=" TextView "       /> </LinearLayout>


MainActivity4

package com.example.listview;import java.util.arraylist;import java.util.hashmap;import  Java.util.list;import java.util.map;import android. R.anim;import android. r.drawable;import android.app.activity;import android.os.bundle;import android.widget.listview; import android.widget.simpleadapter;public class mainactivity4 extends activity{ private listview listview; @Overrideprotected  void oncreate (bundle savedinstancestate)  {// todo auto-generated method stubsuper.oncreate (savedInstanceState); SetContentView (R.LAYOUT.MAIN4); listview= (ListView)  findviewbyid (r.id.listview4_1_1);//contents of a list item map<string,  Object> map=new hashmap<string, object> (); Map.put ("Image",  r.drawable.ic_launcher ); Map.put ("name",  "Zhang San"); Map<string, object> map2=new hashmap<string, object> (); Map2.put ("Image",  r.drawable.ic_lAuncher); Map2.put ("name",  "Harry"); List<map<string, object>> list=new arraylist<map<string,object>> (); List.add (map); List.add (MAP2); Simpleadapter simpleadapter=new simpleadapter (this, list, r.layout.main4_item, new  string [] {"image", "name"}, new int [] {r.id.imageview4_1_1,r.id.textview4 _1_1}); Listview.setadapter (Simpleadapter);}}

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8B/7D/wKiom1hPjF2jZ3mwAAEyHDI1Fko028.png-wh_500x0-wm_3 -wmp_4-s_1450833513.png "title=" W860@308s~]kk_]qh2$$0su.png "alt=" Wkiom1hpjf2jz3mwaaeyhdi1fko028.png-wh_50 "/>

You can also customize adapter

Mian5.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "> <listvie W android:id= "@+id/listview5_1_1" android:layout_width= "match_parent" android:layout_height= "Wrap_co Ntent "></ListView></LinearLayout>

Main5_item.xml

<?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Match_parent "     android:layout_height= "wrap_content"     android:orientation= "Horizontal"      android:gravity= "Center"     ><ImageView      android:id= "@+id/imageview5_1_1"     android:layout_width= "Wrap_content"      android:layout_height= "Wrap_content"     android:src= "@drawable/A"        /><textview     android:id= "@+id/textView5_1_1"      android:layout_width= "Match_parent"     android:layout_height= "Wrap_ Content "    android:text=" TextView "       /></ Linearlayout>

MainActivity5

package com.example.listview;import android.app.activity;import android.os.bundle;import  android.view.layoutinflater;import android.view.view;import android.view.viewgroup;import  Android.widget.baseadapter;import android.widget.imageview;import android.widget.listview;import  android.widget.textview;public class mainactivity5 extends activity  { private listview listview;//defines the data private int [] images={r.drawable.ic_launcher, R.drawable.ic_launcher};p rivate string [] names={"Xiaobai", "xiaoming"}; @Overrideprotected   Void oncreate (bundle savedinstancestate)  {// TODO Auto-generated method  Stubsuper.oncreate (savedinstancestate); Setcontentview (R.LAYOUT.MAIN5); listview= (ListView)  findviewbyid ( r.id.listview5_1_1); Listview.setadapter (New myadapter ());} Custom Adapter class myadapter extends baseadapter{//Gets the total number of list items @overridepubliC int getcount ()  {// TODO Auto-generated method stubreturn  Names.length;} Get each list item (obtained according to subscript) @Overridepublic  object getitem (int position)  {// TODO  Auto-generated method stubreturn names[position];} Get Id@overridepublic long getitemid (int position) For each list item  {// TODO  Auto-generated method stubreturn position;} @Overridepublic  view getview (int position, view convertview, viewgroup  Parent)  {// todo auto-generated method stub//get the layout filler layoutinflater  Layoutinflater=getlayoutinflater ();//Get Main5_item Layout template view view=layoutinflater.inflate (R.layout.main5_ Item, null);//Find corresponding viewimageview imageview= (ImageView)  view.findviewbyid from the resulting view (r.id.imageview5 _1_1); textview textview= (TextView)  view.findviewbyid (r.id.textview5_1_1); Imageview.setimageresource (Images [position]); Textview.settexT (Names[position]); return view;}}} 

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8B/7F/wKiom1hPodCiVuORAAETEysYaOc120.png-wh_500x0-wm_3 -wmp_4-s_4252185371.png "title="]]38n%p ($6_]sdlm0mkhw{r.png "alt=" Wkiom1hpodcivuoraaeteysyaoc120.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8B/7F/wKiom1hPowizBeJkAACZ3uL2WSY390.png-wh_500x0-wm_3 -wmp_4-s_3160887709.png "title=" capture. PNG "alt=" Wkiom1hpowizbejkaacz3ul2wsy390.png-wh_50 "/>

This way, the GetView () method is called multiple times

This article is from the "matengbing" blog, make sure to keep this source http://matengbing.blog.51cto.com/11395502/1882233

Android ListView graphic mash-up

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.