Android Listview异步动态加载网络图片
应用实例:解析后台返回的数据,把每条都显示在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的易做图
[代码] (1)定义类MapListImageAndText管理ListViewItem中控件的内容
01 package com.google.zxing.client.android.AsyncLoadImage;
02
03
04
05 public class MapListImageAndText {
06 private String imageUrl;
07 private String shopname;
08 private String activitynifo;
09 private String address;
10 private String telephone;
11 private String distance;
12
13 public MapListImageAndText(String imageUrl, String shopname, String activitynifo, String address, String telephone,String distance) {
14 this.imageUrl = imageUrl;
15 this.shopname = shopname;
16 this.activitynifo = activitynifo;
17 this.address = address;
18 this.telephone = telephone;
19 this.distance=distance;
20 }
21
22 public String getImageUrl() {
23 return imageUrl;
24 }
25
26 public String getShopname() {
27 return shopname;
28 }
29
30 public String getActivitynifo() {
31 return activitynifo;
32 }
33
34 public String getAddress() {
35 return address;
36 }
37
38 public String getTelephone() {
39 return telephone;
40 }
41
42 public String getDistance() {
43 return distance;
44 }
45
46
47 }
[代码] (2)定义类MapListViewCache实例化ListViewItem中的控件
01 package com.google.zxing.c
补充:移动开发 , Android ,