<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    風人園

    弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
    隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
    數(shù)據(jù)加載中……

    Android之SimpleAdapter簡單實例和SimpleAdapter參數(shù)說明(zt)

    http://blog.csdn.net/x605940745/article/details/11981049

    SimpleAdapter的參數(shù)說明
     第一個參數(shù) 表示訪問整個android應用程序接口,基本上所有的組件都需要
     第二個參數(shù)表示生成一個Map(String ,Object)列表選項
     第三個參數(shù)表示界面布局的id  表示該文件作為列表項的組件
     第四個參數(shù)表示該Map對象的哪些key對應value來生成列表項
     第五個參數(shù)表示來填充的組件 Map對象key對應的資源一依次填充組件 順序有對應關系
     注意的是map對象可以key可以找不到 但組件的必須要有資源填充  因為 找不到key也會返回null 其實就相當于給了一個null資源
     下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head}
    這個head的組件會被name資源覆蓋


    代碼

    [html] view plain copy
     在CODE上查看代碼片派生到我的代碼片
    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     xmlns:tools="http://schemas.android.com/tools"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:orientation="horizontal"  
    6.     tools:context=".MainActivity" >  
    7.   
    8.     <ListView  
    9.         android:id="@+id/lt1"  
    10.         android:layout_width="match_parent"  
    11.         android:layout_height="wrap_content" >  
    12.     </ListView>  
    13.   
    14. </LinearLayout>  

    [html] view plain copy
     在CODE上查看代碼片派生到我的代碼片
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:orientation="horizontal" >  
    6.   
    7.     <ImageView  
    8.         android:id="@+id/head"  
    9.         android:layout_width="wrap_content"  
    10.         android:layout_height="wrap_content"  
    11.         android:paddingLeft="10dp" />  
    12.   
    13.     <LinearLayout  
    14.         android:layout_width="match_parent"  
    15.         android:layout_height="wrap_content"  
    16.         android:orientation="vertical" >  
    17.           
    18.         <TextView   
    19.             android:id="@+id/name"  
    20.             android:layout_width="wrap_content"  
    21.             android:layout_height="wrap_content"  
    22.             android:textSize="20dp"  
    23.             android:textColor="#f0f"  
    24.             android:paddingLeft="10dp"/>  
    25.           
    26.                   
    27.         <TextView   
    28.             android:id="@+id/desc"  
    29.             android:layout_width="wrap_content"  
    30.             android:layout_height="wrap_content"  
    31.             android:textSize="14dp"  
    32.             android:paddingLeft="10dp"/>  
    33.           
    34.     </LinearLayout>  
    35.   
    36. </LinearLayout>  


    [java] view plain copy
     在CODE上查看代碼片派生到我的代碼片
    1. package com.example.simpleadptertest;  
    2.   
    3. import java.util.ArrayList;  
    4. import java.util.HashMap;  
    5. import java.util.List;  
    6. import java.util.Map;  
    7.   
    8. import android.app.Activity;  
    9. import android.os.Bundle;  
    10. import android.view.Menu;  
    11. import android.widget.ListView;  
    12. import android.widget.SimpleAdapter;  
    13.   
    14. public class MainActivity extends Activity {  
    15.   
    16.     private String[] name = { "劍蕭舞蝶""張三""hello""詩情畫意" };  
    17.   
    18.     private String[] desc = { "魔域玩家""百家執(zhí)行""高級的富一代""妹子請過來..一個善于跑妹子的。。" };  
    19.   
    20.     private int[] imageids = { R.drawable.libai, R.drawable.nongyu,  
    21.             R.drawable.qingzhao, R.drawable.tiger };  
    22.       
    23.     private ListView lt1;  
    24.   
    25.     @Override  
    26.     protected void onCreate(Bundle savedInstanceState) {  
    27.         super.onCreate(savedInstanceState);  
    28.         setContentView(R.layout.activity_main);  
    29.         List<Map<String, Object>> listems = new ArrayList<Map<String, Object>>();  
    30.         for (int i = 0; i < name.length; i++) {  
    31.             Map<String, Object> listem = new HashMap<String, Object>();  
    32.             listem.put("head", imageids[i]);  
    33.             listem.put("name", name[i]);  
    34.             listem.put("desc", desc[i]);  
    35.             listems.add(listem);  
    36.         }  
    37.           
    38.         /*SimpleAdapter的參數(shù)說明 
    39.          * 第一個參數(shù) 表示訪問整個android應用程序接口,基本上所有的組件都需要 
    40.          * 第二個參數(shù)表示生成一個Map(String ,Object)列表選項 
    41.          * 第三個參數(shù)表示界面布局的id  表示該文件作為列表項的組件 
    42.          * 第四個參數(shù)表示該Map對象的哪些key對應value來生成列表項 
    43.          * 第五個參數(shù)表示來填充的組件 Map對象key對應的資源一依次填充組件 順序有對應關系 
    44.          * 注意的是map對象可以key可以找不到 但組件的必須要有資源填充  因為 找不到key也會返回null 其實就相當于給了一個null資源 
    45.          * 下面的程序中如果 new String[] { "name", "head", "desc","name" } new int[] {R.id.name,R.id.head,R.id.desc,R.id.head} 
    46.          * 這個head的組件會被name資源覆蓋 
    47.          * */  
    48.         SimpleAdapter simplead = new SimpleAdapter(this, listems,  
    49.                 R.layout.simple_item, new String[] { "name""head""desc" },  
    50.                 new int[] {R.id.name,R.id.head,R.id.desc});  
    51.           
    52.         lt1=(ListView)findViewById(R.id.lt1);  
    53.         lt1.setAdapter(simplead);  
    54.           
    55.     }  
    56.   
    57.     @Override  
    58.     public boolean onCreateOptionsMenu(Menu menu) {  
    59.         // Inflate the menu; this adds items to the action bar if it is present.  
    60.         getMenuInflater().inflate(R.menu.main, menu);  
    61.         return true;  
    62.     }  
    63.   
    64. }  


    posted on 2016-12-01 13:12 風人園 閱讀(181) 評論(0)  編輯  收藏 所屬分類: Android

    主站蜘蛛池模板: 国产亚洲高清在线精品不卡| 精品免费视在线观看| www国产亚洲精品久久久| 久久久免费观成人影院| 久久精品国产亚洲AV无码娇色 | 91精品国产亚洲爽啪在线观看| 精品国产污污免费网站aⅴ | 最近更新免费中文字幕大全| 亚洲码一区二区三区| 免费国产综合视频在线看| 免费av一区二区三区| 亚洲色大成网站www尤物| 日韩一卡2卡3卡4卡新区亚洲| 在线视频精品免费| 本道天堂成在人线av无码免费| 色播亚洲视频在线观看| 国产午夜免费秋霞影院| 久久国产乱子免费精品| 美女被免费视频网站a| 精品亚洲成AV人在线观看| 国产精品冒白浆免费视频| 久久青草国产免费观看| 黄页网址在线免费观看| 亚洲成av人片不卡无码| 在线观看国产区亚洲一区成人 | 亚洲精品无码专区2| 91在线视频免费91| 免费黄色电影在线观看| 深夜福利在线视频免费| 亚洲精品中文字幕无乱码麻豆| 国产亚洲精品a在线无码| 国产女高清在线看免费观看| 九九精品免费视频| 久久永久免费人妻精品下载| 久久嫩草影院免费看夜色| 美国免费高清一级毛片| 亚洲精品伊人久久久久| 亚洲福利一区二区三区| 久久亚洲精品成人777大小说| 亚洲视频一区二区| 国产婷婷高清在线观看免费|