<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

    主站蜘蛛池模板: 亚洲AV永久无码精品一福利| 国产成人亚洲午夜电影| 亚洲春色在线观看| 97久久国产亚洲精品超碰热| 亚洲国产av玩弄放荡人妇| 黄视频在线观看免费| 四虎在线视频免费观看视频| 免费人成激情视频| 内射少妇36P亚洲区| 国产成人亚洲精品无码AV大片| 免费国产一级特黄久久| 亚洲av日韩综合一区二区三区| 免费在线观看你懂的| 国产成人无码免费看片软件 | 色影音免费色资源| 亚洲欧洲久久av| 亚洲乱码中文论理电影| 99热在线日韩精品免费| 国产裸模视频免费区无码| 亚洲黄色三级视频| 国产无遮挡无码视频免费软件| 日韩高清免费在线观看| 亚洲成A∨人片在线观看无码| 免费阿v网站在线观看g| 亚洲精品视频久久| 日韩免费观看一区| 国产亚洲精品美女久久久| 羞羞视频在线免费观看| 麻豆国产精品入口免费观看| 亚洲乱码中文字幕小综合| 全部免费毛片免费播放| 岛国岛国免费V片在线观看| 久久亚洲中文字幕精品一区| 国产成人综合久久精品亚洲| 亚洲最大激情中文字幕| 精选影视免费在线 | 亚洲另类图片另类电影| 亚洲免费一区二区| 最近最新MV在线观看免费高清| 亚洲成人黄色在线| 亚洲日韩国产精品乱|