SimpleAdapter
来源:互联网 发布:qq2012国际版 linux 编辑:程序博客网 时间:2024/05/18 11:16
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <ListView android:id="@+id/main_lv" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
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="horizontal" > <ImageView android:id="@+id/tx_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="25dp" android:src="@drawable/btn_plus_disable" /> <TextView android:id="@+id/tx_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="25dp" android:text="我是名字" android:textSize="20dip" /> <TextView android:id="@+id/tx_address" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是地址" android:textSize="20dip" /></LinearLayout>
MainActivity.java
package com.demo.simpleadapter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.ListView;import android.widget.SimpleAdapter;public class MainActivity extends Activity {private ListView listView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);listView = (ListView) findViewById(R.id.main_lv);List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();Map<String, Object> map1 = new HashMap<String, Object>();map1.put("name", "杨幂");map1.put("address", "北京");map1.put("photo", R.drawable.btn_plus_disable);Map<String, Object> map2 = new HashMap<String, Object>();map2.put("name", "刘亦菲");map2.put("address", "北京");map2.put("photo", R.drawable.btn_radio_off_pressed);Map<String, Object> map3 = new HashMap<String, Object>();map3.put("name", "景甜");map3.put("address", "北京");map3.put("photo", R.drawable.btn_rating_star_off_pressed_holo_light);data.add(map1);data.add(map2);data.add(map3);listView.setAdapter(new SimpleAdapter(this, data, R.layout.list_view,new String[]{"photo","name","address"},new int[]{R.id.tx_img,R.id.tx_name,R.id.tx_address} ));}}
效果图:
0 0
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- simpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- SimpleAdapter
- 4.7 电源管理 第五部分 ---- Windows CE设备驱动开发之电源管理
- CDC类
- POJ 2632: Crashing Robots 哎呀!撞了!
- Partition List
- 给大家分享5个关于迅猛增长的实际例子
- SimpleAdapter
- UVa 10603 - Fill
- POJ 1321 经典棋盘问题 的搜索和状态压缩解法
- 程序员永远的痛之字符编码的奥秘
- PAT OJ 刷题小结~~
- C++的const类成员函数
- HelloWorld
- 利用shell脚本监听某些远程主机的磁盘状况
- Android教程之如何使用自定义字体