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

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

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

    風人園

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

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

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

    SimpleAdapter的參數說明
     第一個參數 表示訪問整個android應用程序接口,基本上所有的組件都需要
     第二個參數表示生成一個Map(String ,Object)列表選項
     第三個參數表示界面布局的id  表示該文件作為列表項的組件
     第四個參數表示該Map對象的哪些key對應value來生成列表項
     第五個參數表示來填充的組件 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 = { "魔域玩家""百家執行""高級的富一代""妹子請過來..一個善于跑妹子的。。" };  
    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的參數說明 
    39.          * 第一個參數 表示訪問整個android應用程序接口,基本上所有的組件都需要 
    40.          * 第二個參數表示生成一個Map(String ,Object)列表選項 
    41.          * 第三個參數表示界面布局的id  表示該文件作為列表項的組件 
    42.          * 第四個參數表示該Map對象的哪些key對應value來生成列表項 
    43.          * 第五個參數表示來填充的組件 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

    主站蜘蛛池模板: 成人免费777777被爆出| 国产午夜亚洲精品国产| 亚洲AV无码国产精品色午友在线 | 亚洲AV无码一区二区三区久久精品 | 成全在线观看免费观看大全 | 亚洲三级在线播放| 亚洲av无码一区二区三区观看| 亚洲特级aaaaaa毛片| 亚洲电影免费观看| 亚洲天堂免费在线| 亚洲欧美国产国产一区二区三区| 亚洲码和欧洲码一码二码三码| 亚洲AV无码一区二区三区网址| 曰批免费视频播放在线看片二| 一级做a爰全过程免费视频毛片| 好湿好大好紧好爽免费视频| 成人爽a毛片免费| 久久A级毛片免费观看| A在线观看免费网站大全| 成人免费男女视频网站慢动作| 国产男女猛烈无遮挡免费网站| 亚洲精品网站在线观看不卡无广告| 久久99亚洲综合精品首页 | 又爽又黄无遮挡高清免费视频| 亚洲人成人无码网www国产| 亚洲啪啪AV无码片| 色拍自拍亚洲综合图区| 亚洲AV成人影视在线观看| 国产精品亚洲综合一区在线观看 | 亚洲一区二区三区四区视频| 亚洲成在人线在线播放无码| 免费无码午夜福利片| 日批视频网址免费观看| 1000部拍拍拍18勿入免费视频下载 | 国产在线精品观看免费观看| 精品无码AV无码免费专区| 9久9久女女免费精品视频在线观看| 在线观看亚洲免费| 一本久久a久久精品亚洲| 亚洲大香人伊一本线| 国产成人高清亚洲一区久久|