android listview从网络获取图片及文字显示,Android中listview加载网络图片.doc

Android中listview加载网络图片.doc

1.主Activity

public class MainActivity extends Activity {

private ListView listView;

private ArrayList persons;

private ListAdapter adapter;

private Handler handler=null;

//xml文件的网络地址

final String path="0:8080/FileServer/person.xml";

@SuppressLint("HandlerLeak")

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

listView=(ListView) super.findViewById(R.id.listview);

//cache=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/cache");

//开一条子线程加载网络数据

Runnable runnable=new Runnable()

{

public void run()

{

try

{

Thread.sleep(2000);

//xmlwebData解析网络中xml中的数据

persons=XmlwebData.getData(path);

//发送消息,并把persons结合对象传递过去

handler.sendMessage(handler.obtainMessage(0, persons));

}

catch (InterruptedException e)

{

e.printStackTrace();

}

}

};

try

{

//开启线程

new Thread(runnable).start();

//handler与线程之间的通信及数据处理

handler=new Handler()

{

public void handleMessage(Message msg)

{

if(msg.what==0)

{

//msg.obj是获取handler发送信息传来的数据

@SuppressWarnings("unchecked")

ArrayList person=(ArrayList) msg.obj;

//给ListView绑定数据

BinderListData(person);

}

}

};

}

catch (Exception e)

{

e.printStackTrace();

}

}

//绑定数据

public void BinderListData(ArrayList person

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值