Android Course---optimized listview list view

Source: Internet
Author: User

Activity_ui4.xml

<? XML version= "1.0" encoding= "Utf-8" ?> <  xmlns:android= "http://schemas.android.com/apk/res/android"    Android:layout_ Width= "Match_parent"    android:layout_height= "Match_parent"     Android:id= "@+id/sa_1"></ListView>

Layout_simple.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= "Wrap_content">    <ImageViewAndroid:layout_width= "70DP"Android:layout_height= "70DP"android:src= "@drawable/yuantu"Android:id= "@+id/lv2"/>    <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= "Food Pictures"Android:id= "@+id/tv1"/>        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "very tasty."Android:id= "@+id/tv2"/>    </LinearLayout></LinearLayout>

Uiactivity4.java

 PackageCom.hanqi.test5;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.widget.ListView;ImportAndroid.widget.SimpleAdapter;Importjava.util.ArrayList;Importjava.util.Hashtable;Importjava.util.List;ImportJava.util.Map; Public classUIActivity4extendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_UI4); ListView sa_1=(ListView) Findviewbyid (r.id.sa_1); //preparing the data sourcelist<map<string,object>> LM =NewArraylist<map<string,object>>(); Map<String,Object> map =NewHashtable<string, object>(); Map.put ("Image", R.drawable.yuantu); Map.put ("Name", "Gourmet picture 01"); Map.put ("Content", "very good 01");        Lm.add (map); Map=NewHashtable<string, object>(); Map.put ("Image", R.drawable.yuantu); Map.put ("Name", "Gourmet picture 02"); Map.put ("Content", "very good 02");        Lm.add (map); Map=NewHashtable<string, object>(); Map.put ("Image", R.drawable.yuantu); Map.put ("Name", "Gourmet picture 03"); Map.put ("Content", "very good 03");        Lm.add (map); Map=NewHashtable<string, object>(); Map.put ("Image", R.drawable.yuantu); Map.put ("Name", "Gourmet picture 04"); Map.put ("Content", "very good 04");        Lm.add (map); //1. The key array in the array sourcestring[] Str ={"image", "name", "content"}; //the ID of the face view in the 2.layout file        int[] Viewid ={R.ID.LV2,R.ID.TV1,R.ID.TV2,}; Simpleadapter SA=NewSimpleadapter ( This, Lm,r.layout.layout_simple,str,viewid);    Sa_1.setadapter (SA); }}

Android Course---optimized listview list view

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.