zoukankan      html  css  js  c++  java
  • android listview 三种适配器设置

    1:

    1. public class ArrayAdapterActivity extends ListActivity {  
    2.     @Override  
    3.     public void onCreate(Bundle savedInstanceState) {  
    4.         super.onCreate(savedInstanceState);  
    5.         //列表项的数据  
    6.         String[] strs = {"1","2","3","4","5"};  
    7.         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,strs);  
    8.         setListAdapter(adapter);  
    9.     }  



    2:
    xml
    1. <?xml version="1.0" encoding="utf-8"?> 
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    3.     android:orientation="vertical" 
    4.     android:layout_width="fill_parent" 
    5.     android:layout_height="fill_parent" 
    6.     > 
    7. <ImageView 
    8.     android:id="@+id/img" 
    9.     android:layout_width="wrap_content" 
    10.     android:layout_height="wrap_content" 
    11.     android:layout_margin="5dp" 
    12.     /> 
    13. <TextView 
    14.     android:id="@+id/title" 
    15.     android:layout_width="wrap_content"   
    16.     android:layout_height="wrap_content"   
    17.     android:textColor="#ffffff" 
    18.     android:textSize="20sp" 
    19.     /> 
    20. </LinearLayout> 

    代码

    1. public class SimpleAdapterActivity extends ListActivity {  
    2.     @Override  
    3.     public void onCreate(Bundle savedInstanceState) {  
    4.         super.onCreate(savedInstanceState);  
    5.           
    6.         SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.simple, new String[] { "title",  "img" }, new int[] { R.id.title, R.id.img });  
    7.         setListAdapter(adapter);  
    8.     }  
    9.       
    10.     private List<Map<String, Object>> getData() {  
    11.         //map.put(参数名字,参数值)  
    12.         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();  
    13.         Map<String, Object> map = new HashMap<String, Object>();  
    14.         map.put("title", "摩托罗拉");  
    15.         map.put("img", R.drawable.icon);  
    16.         list.add(map);  
    17.           
    18.         map = new HashMap<String, Object>();  
    19.         map.put("title", "诺基亚");  
    20.         map.put("img", R.drawable.icon);  
    21.         list.add(map);  
    22.           
    23.         map = new HashMap<String, Object>();  
    24.         map.put("title", "三星");  
    25.         map.put("img", R.drawable.icon);  
    26.         list.add(map);  
    27.         return list;  
    28.         }    





    3:
    1. public class SimpleCursorAdapterActivity extends ListActivity {  
    2.     @Override  
    3.     public void onCreate(Bundle savedInstanceState) {  
    4.         super.onCreate(savedInstanceState);  
    5.         //获得一个指向系统通讯录数据库的Cursor对象获得数据来源  
    6.         Cursor cur = getContentResolver().query(People.CONTENT_URI, null, null, null, null);  
    7.         startManagingCursor(cur);  
    8.         //实例化列表适配器  
    9.           
    10.         ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cur, new String[] {People.NAME}, new int[] {android.R.id.text1});  
    11.         setListAdapter(adapter);  
    12.     }  


  • 相关阅读:
    Java高级之类结构的认识
    14.8.9 Clustered and Secondary Indexes
    14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器
    14.8.3 Physical Row Structure of InnoDB Tables InnoDB 表的物理行结构
    14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用
    14.8.1 Creating InnoDB Tables 创建InnoDB 表
    14.7.4 InnoDB File-Per-Table Tablespaces
    14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小
    14.7.1 Resizing the InnoDB System Tablespace InnoDB 系统表空间大小
    14.6.11 Configuring Optimizer Statistics for InnoDB 配置优化统计信息用于InnoDB
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3214899.html
Copyright © 2011-2022 走看看