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.     }  


更多相关文章

  1. Android中数据的保存和提取
  2. android-数据库操作实例,留着以后用
  3. Android之数据库
  4. Android与服务器传递数据
  5. Android的几种数据存储方式
  6. android客户端通过Get方式提交参数给服务器,使用URL和HttpURLConn
  7. Android中intent如何传递自定义数据类型
  8. android使用notifyDataSetChanged()方法,adapter的数据更新了,但是
  9. Android 数据存储之SQLite数据库

随机推荐

  1. AppCompat实现Action Bar
  2. android volley封装及源码解析
  3. Android 导航类型
  4. Android中如何实现图像的闪动
  5. Android经常使用开源组件汇总
  6. LinearLayout 线性布局
  7. android 中 LocalSocket的基本使用方法
  8. Android 2.3 Rotation and Orientation
  9. android百度地图半径画圆
  10. Android java List 转Json格式