您的位置:首页 > 移动开发 > Android开发

应用实例:解析后台返回的数据,把每条都显示在ListView中,包括活动图片、店名、活动详情、地址、电话和距离等。

2012-05-28 13:05 741 查看
应用实例:解析后台返回的数据,把每条都显示在ListView中,包括活动图片、店名、活动详情、地址、电话和距离等。

 

在布局文件中ListView的定义:

<ListView android:id="@id/maplistview" android:background="@drawable/bg" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000"  android:divider="@drawable/separator" android:dividerHeight="2.0px" android:layout_below="@id/mapseparator"/>

 

在布局文件ListViewItem,中定义活动图片、店名、活动详情、地址、电话和距离的布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingBottom="2dip"
android:paddingLeft="2dip" android:paddingRight="2dip">

<ImageView android:paddingTop="2dip" android:layout_alignParentLeft="true" android:layout_width="80px"  android:layout_height="80px" android:id="@+id/maplistviewitemImage"/>

<TextView android:layout_height="wrap_content" android:textSize="17dip" android:layout_width="fill_parent" android:id="@+id/maplistviewitemshopname"android:layout_toRightOf="@id/maplistviewitemImage"android:textColor="#000000"/>

<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/maplistviewitemImage" android:id="@+id/maplistviewitemActi" android:textColor="#6C6C6C"/>

<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/maplistviewitemActi" android:id="@+id/maplistviewitemaddr" android:textColor="#6C6C6C" android:singleLine="true"/>

<TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/maplistviewitemaddr" android:id="@+id/maplistviewitemtelphone" android:textColor="#6C6C6C" android:singleLine="true"/>

</RelativeLayout>

 

(1)定义类MapListImageAndText管理ListViewItem中控件的内容

(2)定义类MapListViewCache实例化ListViewItem中的控件

(3)定义类AsyncImageLoader,开启线程下载指定图片

(4)定义类MapListImageAndTextListAdapter继承ArrayAdapter,用于创建AsyncImageLoader实例,并指定控件的内容

(5)主程序中Listview与MapListImageAndTextListAdapter的捆绑

代码部分详见:http://www.oschina.net/code/snippet_176897_7207
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐