7 simpleAdapter的原理和使用
来源:互联网 发布:虚拟试衣软件下载 编辑:程序博客网 时间:2024/06/05 16:33
布局和listView布局文件。
<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/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" ></ListView> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="名字" /> <TextView android:id="@+id/phone"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:text="电话" /></RelativeLayout>
使用SimpleAdapter进行数据展现
package org.sicn.lee.contentvaluedemo;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.sicn.lee.dao.PersonDAO;import org.sicn.lee.domain.Person;import android.app.Activity;import android.os.Bundle;import android.widget.ListView;import android.widget.SimpleAdapter;public class MainActivity extends Activity {private ListView lv;private PersonDAO dao;private List<Person> list;private List<Map<String,String>> listMap;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(R.layout.activity_main);this.lv=(ListView) super.findViewById(R.id.lv);dao=new PersonDAO(this);list=dao.findAll("person", null, null, null, null, null, null);listMap=new ArrayList<Map<String,String>>();Map<String,String> map=new HashMap<String,String>();Iterator<Person> iter=list.iterator();while(iter.hasNext()){Person person=iter.next();map.put("name", person.getName());map.put("phone",person.getPhone());listMap.add(map);}this.lv.setAdapter(new SimpleAdapter(this, listMap,R.layout.person_item,new String[]{"name","phone"},new int[]{R.id.name,R.id.phone}));}}
0 0
- 7 simpleAdapter的原理和使用
- simpleAdapter的原理及使用
- SimpleAdapter 和 SimpleCursorAdapter的使用
- ArrayAdapter, SimpleAdapter 和BaseAdapter的使用范例
- Adapter的arrayladapter和simpleadapter使用
- Android SimpleAdapter 的详解和使用
- BaseAdapter(和SimpleAdapter)的使用
- 20.ArrayAdapter和SimpleAdapter的使用
- 使用ArrayAdapter和SimpleAdapter
- SimpleAdapter适配器的使用
- SimpleAdapter的基本使用
- ListView -- SimpleAdapter的使用
- simpleAdapter的使用
- simpleAdapter的使用
- SimpleAdapter的使用
- SimpleAdapter的使用
- SimpleAdapter的简单使用
- SimpleAdapter的使用
- Fragment用法
- 防火墙相关命令
- CCLabelTTF之换行
- 黑马程序员_IO流二
- Linux启动svn服务
- 7 simpleAdapter的原理和使用
- invoke MessgaeBox
- VirtualBox下ubuntu和本机win7共享文件夹
- 快,体现了真正的掌握
- C程序内存分配
- 黑马程序员_GUI
- ios如何获得停止动画
- 互联网创业选择上海还是北京?
- html校验2