View (views)--listview Simpleadapter

Source: Internet
Author: User

I. Concept

A list view, a viewgroup used to display multiple sliding item lists, and an adapter adapter to dynamically adapt the data in the collection and the layout of each item to the ListView for display.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Android:paddingbottom= "@dimen/activity_vertical_margin"7 Android:paddingleft= "@dimen/activity_horizontal_margin"8 Android:paddingright= "@dimen/activity_horizontal_margin"9 Android:paddingtop= "@dimen/activity_vertical_margin"Ten Tools:context= "Com.example.wang.testapp2.TestActivity8"> One  A     <ListView -         Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" the Android:id= "@+id/lv_2"> -     </ListView> -  - </LinearLayout>
Activity.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent">5 6     <ImageView7         Android:layout_width= "70DP"8 Android:layout_height= "70DP"9 android:src= "@drawable/f1"Ten Android:id= "@+id/iv_2"/> One     <LinearLayout A         Android:layout_width= "0DP" - Android:layout_height= "Match_parent" - Android:layout_weight= "1" the android:orientation= "vertical" - Android:layout_marginleft= "20DP" - android:gravity= "Center_vertical"> -  +         <TextView -             Android:layout_width= "Match_parent" + Android:layout_height= "Wrap_content" A Android:text= "Name =aaa" at Android:id= "@+id/tv_7"/> -  -         <TextView -             Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:text= "Content =aaa" in Android:id= "@+id/tv_8"/> -  to     </LinearLayout> +  - </LinearLayout>
Simple_adapter
1  Packagecom.example.wang.testapp2;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 ImportAndroid.widget.ListView;6 ImportAndroid.widget.SimpleAdapter;7 8 Importjava.util.ArrayList;9 ImportJava.util.HashMap;Ten Importjava.util.List; One ImportJava.util.Map; A Importjava.util.Objects; - ImportJava.util.SimpleTimeZone; -  the  Public classTestActivity8extendsappcompatactivity { -  - ListView lv_2; -  + @Override -     protected voidonCreate (Bundle savedinstancestate) { +         Super. OnCreate (savedinstancestate); A Setcontentview (R.LAYOUT.ACTIVITY_TEST8); at  -Lv_2=(ListView) Findviewbyid (r.id.lv_2); -  -         //1. Data set Layout -  -List<map<string,object>> lm=NewArraylist<map<string,object>>(); in  -Map<string,object> map=NewHashmap<string, object>(); toMap.put ("img", R.DRAWABLE.F1); +Map.put ("name", "Gourmet 1"); -Map.put ("Content", "Introduction to Food 1"); the lm.add (map); *  $map=NewHashmap<string, object>();Panax NotoginsengMap.put ("img", R.DRAWABLE.F2); -Map.put ("name", "Gourmet 2"); theMap.put ("Content", "Introduction to Food 2"); + lm.add (map); A  themap=NewHashmap<string, object>(); +Map.put ("img", r.drawable.f3); -Map.put ("name", "Gourmet 3"); $Map.put ("Content", "Introduction to Food 3"); $ lm.add (map); -  -map=NewHashmap<string, object>(); theMap.put ("img", r.drawable.f4); -Map.put ("name", "Gourmet 4");WuyiMap.put ("Content", "Introduction to Food 4"); the lm.add (map); -  Wumap=NewHashmap<string, object>(); -Map.put ("img", r.drawable.f5); AboutMap.put ("name", "Gourmet 5"); $Map.put ("Content", "Introduction to Food 5"); - lm.add (map); -  -map=NewHashmap<string, object>(); AMap.put ("img", R.DRAWABLE.F6); +Map.put ("name", "Gourmet 6"); theMap.put ("Content", "Introduction to Food 6"); - lm.add (map); $  themap=NewHashmap<string, object>(); theMap.put ("img", R.DRAWABLE.F7); theMap.put ("name", "Gourmet 7"); theMap.put ("Content", "Introduction to Food 7"); - lm.add (map); in  themap=NewHashmap<string, object>(); theMap.put ("img", R.drawable.f8); AboutMap.put ("name", "Gourmet 8"); theMap.put ("Content", "Introduction to Food 8"); the lm.add (map); the  +map=NewHashmap<string, object>(); -Map.put ("img", r.drawable.f9); theMap.put ("name", "Gourmet 9");BayiMap.put ("Content", "Introduction to Food 9"); the lm.add (map); the  -map=NewHashmap<string, object>(); -Map.put ("img", R.DRAWABLE.F10); theMap.put ("name", "Gourmet 10"); theMap.put ("Content", "Introduction to Food 10"); the lm.add (map); the  -         //Array of array key theString [] strings={"img", "name", "content"}; the         int[] ids={r.id.iv_2,r.id.tv_7,r.id.tv_8}; the 94         //2. Create Simpleadapter theSimpleadapter simpleadapter=NewSimpleadapter ( This, the lm,r.layout.simple_adapter,strings,ids); the 98 Lv_2.setadapter (simpleadapter); About     } -}
Activity.java

View (views)--listview 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.