zhoukao
来源:互联网 发布:sift算法的opencv代码 编辑:程序博客网 时间:2024/05/23 20:15
package com.bwwei.yukao;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import com.bwei.bean.Student;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Xml;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView lView;
private Student student;
private ArrayList list;
Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
Listlist2= (List) msg.obj;
lView.setAdapter(new Mydater(list2,MainActivity.this));
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lView=(ListView) findViewById(R.id.lv);
//网络解析
new Thread(){
public void run() { getdate(); }; }.start();}protected void getdate() { String path="http://172.17.29.120/localuser/loupengfei/kaoshi/student.xml"; try { XmlPullParser PullParser=Xml.newPullParser(); URL url=new URL(path); try { HttpURLConnection opConnection=(HttpURLConnection) url.openConnection(); opConnection.setRequestMethod("GET"); //联网 opConnection.connect(); InputStream inputStream = opConnection.getInputStream(); try { PullParser.setInput(inputStream, "utf-8"); int eventType = PullParser.getEventType(); while (eventType!=XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_DOCUMENT: list=new ArrayList<Student>(); break; case XmlPullParser.START_TAG: //得到标签名 String names = PullParser.getName(); if ("student".equals(names)) { student=new Student(); String xuehao = PullParser.getAttributeValue(0); student.setXuehao(xuehao); }else if ("name".equals(names)) { String name =PullParser.nextText(); student.setName(name); }else if ("address".equals(names)) { String address =PullParser.nextText(); student.setAddress(address); }else if ("phone".equals(names)) { String phone =PullParser.nextText(); student.setPhone(phone); }else if ("tel".equals(names)) { String tel =PullParser.nextText(); student.setTel(tel); }else if ("school".equals(names)) { String school =PullParser.nextText(); student.setSchool(school); } break; case XmlPullParser.END_TAG: String names1 = PullParser.getName(); if ("student".equals(names1)) { System.out.println(student.toString()); list.add(student); } break; } eventType = PullParser.next(); } Message message=Message.obtain(); message.obj=list; handler.sendMessage(message); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); }}
}
- zhoukao
- 使用LIFERAY的NOTIFICATIONS PORTLET做通知
- Activity进入与退出的动画
- Android 6.0 指纹识别功能学习(一)----阿冬专栏!!!
- java中HashMap,LinkedHashMap,TreeMap,HashTable的区别
- ios 公司账号、企业账号、个人账号的区别
- zhoukao
- weka聚类模型的参数解析
- Java 并发编程深入学习(五)——死锁
- ios新手开发——toast提示和旋转图片加载框
- 互联网公司面试总结
- 蓝鸥Unity开发教程之课时5 Unity组件开发
- C 指针传值
- 本机的环境挂载
- Host文件是什么?host文件有什么作用