首页 > 代码库 > android的liveview装载数据

android的liveview装载数据

设置布局

<?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/itemsTitle"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center_vertical"        android:paddingLeft="10dip"        android:paddingTop="5dip"        android:textColor="@color/gray_black"        android:textSize="18dip" />    <TextView        android:id="@+id/itemsText"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/itemsTitle"        android:gravity="left"        android:paddingBottom="2dip"        android:paddingLeft="10dip"        android:textColor="@color/gray"        android:textSize="15dip" /></RelativeLayout>

 从MAP的集合取数据

 

		//获取数据		Intent intent = getIntent();		Bundle bundle = intent.getExtras();		SerializableMaplist SerializableMaplist = (SerializableMaplist) bundle.get("listdata");		maplist =SerializableMaplist.getMap();  		//填充数据		ListView mListView = (ListView)findViewById(R.id.listview);		//使用自定义的Adapter		MyListViewAdapter myListViewAdapter = new MyListViewAdapter(this, maplist,R.layout.list_items,						new String[] {"rqsj","s","f" ,"JLR"}, 						new int[] {R.id.itemsTitle,R.id.itemsText });			 mListView.setAdapter(myListViewAdapter);

  自定义类MyListViewAdapter

package com.xjx.adapter;import java.util.List;import java.util.Map;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;/** * Copyright (c) 2011 All rights reserved  * 名称:MyListViewAdapter  * 描述:ListView自定义Adapter例子 * @author zhaoqp * @date 2011-11-8 * @version */public class MyListViewAdapter extends BaseAdapter{  	private Context mContext;    //单行的布局    private int mResource;    //列表展现的数据    private List<? extends Map<String, ?>> mData;    //Map中的key    private String[] mFrom;    //view的id    private int[] mTo;       /**    * 构造方法    * @param context    * @param data 列表展现的数据    * @param resource 单行的布局    * @param from Map中的key    * @param to view的id    */    public MyListViewAdapter(Context context, List<? extends Map<String, ?>> data,            int resource, String[] from, int[] to){    	 mContext = context;    	 mData = http://www.mamicode.com/data;"  "+data2.toString()+":"+data3.toString());          holder.itemsText.setText(data4.toString());          return convertView;    }        /**	 * ViewHolder类	 */	static class ViewHolder {		TextView itemsTitle;		TextView itemsText;	}}