应用实例:解析后台返回的数据,把每条都显示在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
在布局文件中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
相关文章推荐
- vc6.0 提取*.lst文件,中函数地址,数据地址,应用实例 红色部分显示
- 玩转Web之Json(三)-----easy ui怎么把前台显示的dataGird中的所有数据序列化为json,返回到后台并解析
- Android访问网络:服务端返回XML或JSON格式数据,Android 进行解析并使用ListView显示
- 玩转Web之Json(三)-----easy ui怎么把前台显示的dataGird中的所有数据序列化为json,返回到后台并解析
- 玩转Web之Json(三)-----easy ui怎么把前台显示的dataGird中的所有数据序列化为json,返回到后台并解析
- easy ui怎么把前台显示的dataGird中的所有数据序列化为json,返回到后台并解析
- JS解析后台返回的JSON格式数据实例
- Android 解析后台返回为Json数据实例教程
- echarts图表中的点、柱形或者折线显示不出来,但是有数据的问题解决(另附后台返回数据实例代码)
- ListView应用------ListView控件显示List集合中的数据,并对Item响应选择事件(法二)
- django后台显示图片 而不是图片地址
- 实例教程八:采用ListView实现数据列表显示
- Android学习 (十八) 用GSON解析JSON数据并在ListView中显示
- 解析JSON数据,并从其中的图片地址取图片
- jQuery树插件zTree.js如何应用后台返回的不标准数据
- Android 解析后台返回为Json数据的简单例子!!!
- 在ASP.NET MVC中json的应用(即JsonResult)(asp.net mvc 后台返回json数据方式 )
- 实现xlistview+xutils展示数据之后点击item跳转页面显示图片缩放和放大
- JAVA调用返回XML格式数据的WebService,并通过XPath解析XML的应用
- iOS开发-自己定义后台显示图片(iOS7-Background Fetch的应用)