Android 应用开发笔记 - 列表(ListView)& SimpleAdapter
来源:互联网 发布:炒股软件开发 编辑:程序博客网 时间:2024/06/08 01:34
1. 新建一Layout XML文件,如下图:
在面板拖拽,更改相关属性,
res/list_view.xml清单如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/listView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:divider="@null" android:dividerHeight="0dp" /></LinearLayout>
2. 新建ListView中行的Layout XML
res/list_row.xml清单如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/imgIcon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="8dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:orientation="vertical" android:paddingLeft="0px" android:paddingRight="5dp" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/title01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:textColor="@color/red" android:textSize="@dimen/font_size24" /> </RelativeLayout> <TextView android:id="@+id/desText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textColor="@color/blue" android:textSize="@dimen/font_size20"/> </LinearLayout> </LinearLayout>
3. 编写代码
(1) 获取各行数据
(2) 新建SimpleAdapter实例
(3) ListView绑定SimpleAdapter
代码如下:
ListView listView = (ListView) findViewById(R.id.listView01);List<Map<String, Object>> data = getSampleData();SimpleAdapter sAdapter = new SimpleAdapter(MainActivity.this, data, R.layout.list_row,new String[] {"imgIcon","title01","desText"},new int[] {R.id.imgIcon,R.id.title01,R.id.desText});listView.setAdapter(sAdapter);
运行效果:
- Android 应用开发笔记 - 列表(ListView)& SimpleAdapter
- Android SimpleAdapter 列表(ListView)、表格(GridView)
- Android列表视图(ListView--SimpleAdapter)学习
- ListView之SimpleAdapter列表
- Android开发之listView使用(手机应用列表显示)
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- Android学习笔记之ListView采用SimpleAdapter
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- ListView应用--SimpleAdapter
- Android学习之listView显示下拉列表(2)(SimpleAdapter适配器)
- Android中使用ListView显示列表之SimpleAdapter的使用
- Android 之 ListView列表控件 的SimpleAdapter适配器
- android(14)(ListView的列表展示,ArrayAdapter,SimpleAdapter)
- ListView.SimpleAdapter笔记
- android 列表开发 ListView
- android:listview SimpleAdapter
- Android--ListView和SimpleAdapter
- Android ListView使用SimpleAdapter
- 链表相邻元素翻转
- JSTL标签 参考手册
- 井号在宏定义中的特殊用法
- 矩形的并和交
- 我和你(3)
- Android 应用开发笔记 - 列表(ListView)& SimpleAdapter
- 秋雨寄相思
- Oracle查询练习及答案
- ibatis调用Oracle中的存储过程和function
- 【STL】inserter和front_inserter的用法
- 黑马程序员——银行业务调度系统
- 不公平的社会
- 《输入一组整数,输出奇数——C#第三周》
- Regex - C++11, 6 of n