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


  • 相关阅读:
    axios解决调用后端接口跨域问题
    vuex的使用入门-官方用例
    vue使用axios实现前后端通信
    vue组件间通信用例
    vue-router的访问权限管理
    vue-router使用入门
    PHP 流程控制
    PHP 表达式和运算符
    PHP 预定义变量
    PHP 常量
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3214899.html
Copyright © 2020-2023  润新知