文档介绍:Android中ListView异步加载数据
1 public class MainActivity extends Activity {
2
3 private ListView listView;
4 private ArrayList persons;
5 private ListAdapter adapter;
6 private Handler handler=null;
7 //xml文件的网络地址
8 final String path=":8080/FileServer/";
9 ***@SuppressLint("HandlerLeak")
10 protected void onCreate(Bundle savedInstanceState) {
11 (savedInstanceState);
12 setContentView();
13
14 listView=(ListView) ();
15 //cache=new File(().getAbsolutePath()+"/cache");
16
17 //开一条子线程加载网络数据
18 Runnable runnable=new Runnable()
19 {
20 public void run()
21 {
22 try
23 {
24 (2000);
25 //xmlwebData解析网络中xml中的数据
26 persons=(path);
27 //发送消息,并把persons结合对象传递过去
28 ((0, persons));
29 }
30 catch (InterruptedException e)
31 {
32 ();
33 }
34 }
35 };
36
37 try
38 {
39 //开启线程
40 new Thread(runnable).start();
41 //handler与线程之间的通信及数据处理
42 handler=new Handler()
43 {
44 public void handleMessage(Message msg)
45 {
46 if(==0)
47 {
48 //
49 ***@SuppressWarnings("unchecked")
50 ArrayList person=(A