1. publicclassHttpGetextendsActivity{
  2.   privateListViewlist;
  3.   EarthQuakeInfoselectedQuake;
  4.   ArrayAdapteradapter;
  5.   ArrayListinfoList=newArrayList();
  6.   @Override
  7.   protectedvoidonCreate(BundlesavedInstanceState){
  8.   super.onCreate(savedInstanceState);
  9.   this.setContentView(R.layout.main);
  10.   //设置listView的内容为infoList
  11.   list=(ListView)this.findViewById(R.id.list);
  12.   adapter=newArrayAdapter(this,android.R.layout.simple_list_item_1,infoList);
  13.   //设置ListView的适配器为adapter
  14.   list.setAdapter(adapter);
  15.   getInfo();//获得infoList的具体内容。
  16.   }
  17.   privatevoidgetInfo(){
  18.   URLurl;
  19.   try{
  20.   Stringfeed=getString(R.string.feed);
  21.   url=newURL(feed);
  22.   URLConnectionconnection=url.openConnection();
  23.   HttpURLConnectionhttpConnection=(HttpURLConnection)connection;
  24.   intresponseCode=httpConnection.getResponseCode();
  25.   if(responseCode==HttpURLConnection.HTTP_OK){
  26.   InputStreamin=httpConnection.getInputStream();
  27.   DocumentBuilderFactorydbfactory=DocumentBuilderFactory.newInstance();
  28.   DocumentBuilderdb=dbfactory.newDocumentBuilder();
  29.   //解析地震feed
  30.   Documentdom=db.parse(in);
  31.   ElementdocEle=dom.getDocumentElement();
  32.   //清空旧的地震信息
  33.   infoList.clear();
  34.   //获得地震信息列表
  35.   NodeListnl=docEle.getElementsByTagName("entry");
  36.   if(nl!=null&&nl.getLength()>0){
  37.   for(inti=0;i<nl.getLength();i++){
  38.   Elemententry=(Element)nl.item(i);
  39.   Elementtitle=(Element)entry.getElementsByTagName("title").item(0);
  40.   Elementgeo=(Element)entry.getElementsByTagName("georss:point").item(0);
  41.   Elementwhen=(Element)entry.getElementsByTagName("updated").item(0);
  42.   Stringdetails=title.getFirstChild().getNodeValue();
  43.   Stringpoint=geo.getFirstChild().getNodeValue();
  44.   Stringdate=when.getFirstChild().getNodeValue();
  45.   SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
  46.   Dateqdate=newGregorianCalendar(0,0,0).getTime();
  47.   try{
  48.   qdate=sdf.parse(date);
  49.   }catch(Exceptione){
  50.   e.printStackTrace();//TODO:handleexception
  51.   }
  52.   String[]location=point.split("");
  53.   Locationloc=newLocation("dummyGPS");
  54.   loc.setLatitude(Double.parseDouble(location[0]));
  55.   loc.setLongitude(Double.parseDouble(location[1]));
  56.   StringmagnitudeString=details.split("")[1];
  57.   intend=magnitudeString.length()-1;
  58.   doublemagnitude=Double.parseDouble(magnitudeString.substring(0,end));
  59.   details=details.split(",")[1].trim();
  60.   EarthQuakeInfoinfo=newEarthQuakeInfo(qdate,details,loc,magnitude);
  61.   //处理地震信息
  62.   newEntry(info);
  63.   }
  64.   }
  65.   }
  66.   }catch(Exceptione){
  67.   //TODO:handleexception
  68.   }
  69.   }
  70.   privatevoidnewEntry(EarthQuakeInfoinfo){
  71.   infoList.add(info);
  72.   adapter.notifyDataSetChanged();
  73.   }
  74.   publicclassEarthQuakeInfo{
  75.   publicDatedate;
  76.   publicStringdetails;
  77.   publicLocationlocation;
  78.   publicdoublemagnitude;
  79.   publicEarthQuakeInfo(Dated,Stringde,Locationloc,doublemag){
  80.   this.date=d;
  81.   this.details=de;
  82.   this.location=loc;
  83.   this.magnitude=mag;
  84.   }
  85.   @Override
  86.   publicStringtoString(){
  87.   SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-dd''hh:mm:ss");
  88.   returnsdf.format(date)+"\n里氏"+magnitude+"级"+details+"地点"+location;
  89.   }
  90.   }
  91.   }

更多相关文章

  1. android系统信息总结
  2. Android中读取短信信息
  3. 取消自动获得焦点和弹出对话框
  4. Android(安卓)谷歌统计
  5. 获得位置信息 android
  6. android中操纵sqlite数据库
  7. Android(安卓)Studio的build.gradle里面的各种版本信息
  8. HttpUrlConnect 响应为空的问题分析
  9. execlp启动android进程命令窗口通过adb shell 进入android 的Lin

随机推荐

  1. Android在layout xml中使用include
  2. Android(安卓)文件的上传
  3. Android 编译系统分析之返璞归真(一)
  4. Android极致优化
  5. Android的多语言文件转IOS多语言文件格式
  6. 安卓系统框架介绍
  7. Android与JNI(一)
  8. textview中自动换行显示文本内容
  9. [Android Studio]-基本快捷键大全
  10. C#开发Android