Android开发之获取web服务器xml数据


Android开发之获取web服务器xml数据

首先我们需要配置J2EE开发环境,并部署web应用viderweb,启动服务

然后开始我们的程序代码

我们的程序大致是获取web服务器xmlàpull解析xmlàListView列表显示数据

添加业务bean类Video

  1. package cn.class3g.domain;  
  2.   
  3.    
  4.   
  5. public class Video {  
  6.   
  7.    private int id;  
  8.   
  9.    private String title;  
  10.   
  11.    private int timeLenght;  
  12.   
  13.    
  14.   
  15.    public Video() {  
  16.   
  17.       super();  
  18.   
  19.       // TODO Auto-generated constructor stub  
  20.   
  21.    }  
  22.   
  23.    
  24.   
  25.    public Video(int id, String title, int timeLenght) {  
  26.   
  27.       super();  
  28.   
  29.       this.id = id;  
  30.   
  31.       this.title = title;  
  32.   
  33.       this.timeLenght = timeLenght;  
  34.   
  35.    }  
  36.   
  37.    
  38.   
  39.    public int getId() {  
  40.   
  41.       return id;  
  42.   
  43.    }  
  44.   
  45.    
  46.   
  47.    public void setId(int id) {  
  48.   
  49.       this.id = id;  
  50.   
  51.    }  
  52.   
  53.    
  54.   
  55.    public String getTitle() {  
  56.   
  57.       return title;  
  58.   
  59.    }  
  60.   
  61.    
  62.   
  63.    public void setTitle(String title) {  
  64.   
  65.       this.title = title;  
  66.   
  67.    }  
  68.   
  69.    
  70.   
  71.    public int getTimeLenght() {  
  72.   
  73.       return timeLenght;  
  74.   
  75.    }  
  76.   
  77.    
  78.   
  79.    public void setTimeLenght(int timeLenght) {  
  80.   
  81.       this.timeLenght = timeLenght;  
  82.   
  83.    }  
  84.   
  85.    
  86.   
  87.    @Override  
  88.   
  89.    public String toString() {  
  90.   
  91.       return "Video [id=" + id + "title=" + title + "timeLenght="  
  92.   
  93.            + timeLenght + "]";  
  94.   
  95.    }  
  96.   
  97.    
  98.   
  99. }  

布局

  1. main.xml  
  2.   
  3. <?xml version="1.0" encoding="utf-8"?>  
  4.   
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  6.   
  7.     android:layout_width="fill_parent"  
  8.   
  9.     android:layout_height="fill_parent"  
  10.   
  11.     android:orientation="vertical" >  
  12.   
  13.    
  14.   
  15.     <ListView  
  16.   
  17.         android:id="@+id/listViewID"  
  18.   
  19.         android:layout_width="fill_parent"  
  20.   
  21.         android:layout_height="wrap_content" >  
  22.   
  23.     </ListView>  
  24.   
  25.    
  26.   
  27. </LinearLayout>  

Item.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   
  5.     android:layout_width="match_parent"  
  6.   
  7.     android:layout_height="match_parent"  
  8.   
  9.     android:orientation="horizontal" >  
  10.   
  11.    
  12.   
  13.     <TextView  
  14.   
  15.         android:id="@+id/titleID"  
  16.   
  17.         android:layout_width="200dp"  
  18.   
  19.         android:layout_height="wrap_content" />  
  20.   
  21.    
  22.   
  23.     <TextView  
  24.   
  25.         android:id="@+id/timelengthID"  
  26.   
  27.         android:layout_width="fill_parent"  
  28.   
  29.         android:layout_height="wrap_content" />  
  30.   
  31.    
  32.   
  33. </LinearLayout>  
  • 1
  • 2
  • 下一页

相关内容