android--List View ListView (ii) simpleadapter

Source: Internet
Author: User

Simpleadapter: can display text plus picture

Activity_activitysimple.xml
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "120DP"    >    <ImageViewAndroid:layout_width= "80DP"Android:layout_height= "80DP"android:src= "@drawable/anniu5"android:layout_gravity= "Center_vertical"Android:id= "@+id/iv_1"/>    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "vertical"android:layout_gravity= "Center_vertical"Android:layout_marginleft= "20DP"        >        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Life is Precious"android:textsize= "20DP"Android:id= "@+id/tv_1"/>        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Safe exit"android:textsize= "20DP"Android:id= "@+id/tv_2"/>    </LinearLayout></LinearLayout>

Activitysimple.java

 Packagecom.example.chenshuai.test321;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.ListView;ImportAndroid.widget.SimpleAdapter;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map; Public classActivitysimpleextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_activitysimple); ListView Simple_1=(ListView) Findviewbyid (r.id.simple_1); //preparing the data sourceList<map<string,object>> im =NewArraylist<map<string,object>>(); Map<String,Object> map =NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU3); Map.put ("Name", "Safe exit 1"); Map.put ("Content", "Protecting Life 1");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU4); Map.put ("Name", "Safe Exit 2"); Map.put ("Content", "Protecting Life 2");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU5); Map.put ("Name", "Safe Exit 3"); Map.put ("Content", "Protecting Life 3");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.drawable.anniu6); Map.put ("Name", "Safe Exit 4"); Map.put ("Content", "Protecting Life 4");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU7); Map.put ("Name", "Safe Exit 5"); Map.put ("Content", "Protecting Life 5");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", r.drawable.anniu8); Map.put ("Name", "Safe Exit 6"); Map.put ("Content", "Protecting Life 6");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU9); Map.put ("Name", "Safe Exit 7"); Map.put ("Content", "Protecting Life 7");        Im.add (map); Map=NewHashmap<string,object>(); Map.put ("Image", R.DRAWABLE.ANNIU10); Map.put ("Name", "Safe Exit 8"); Map.put ("Content", "Protecting Life 8");        Im.add (map); //1. An array of keys in the data sourceString str[] = {"Image", "name", "content"}; //the ID key of the face view in the 2.layout file corresponds to value        int[] Viewid ={r.id.iv_1,r.id.tv_1,r.id.tv_2}; simpleadapter simpleadapter = new simpleadapter (  This , im,r.layout.simple_layout,str,viewid);    Simple_1.setadapter (Simpleadapter); }}

android--List View ListView (ii) simpleadapter

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.