歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發之獲取web服務器xml數據

Android開發之獲取web服務器xml數據

日期:2017/3/1 10:45:19   编辑:Linux編程

Android開發之獲取web服務器xml數據

首先我們需要配置J2EE開發環境,並部署web應用viderweb,啟動服務

然後開始我們的程序代碼

我們的程序大致是獲取web服務器xmlàpull解析xmlàListView列表顯示數據

添加業務bean類Video

  1. package cn.class3g.domain;
  2. public class Video {
  3. private int id;
  4. private String title;
  5. private int timeLenght;
  6. public Video() {
  7. super();
  8. // TODO Auto-generated constructor stub
  9. }
  10. public Video(int id, String title, int timeLenght) {
  11. super();
  12. this.id = id;
  13. this.title = title;
  14. this.timeLenght = timeLenght;
  15. }
  16. public int getId() {
  17. return id;
  18. }
  19. public void setId(int id) {
  20. this.id = id;
  21. }
  22. public String getTitle() {
  23. return title;
  24. }
  25. public void setTitle(String title) {
  26. this.title = title;
  27. }
  28. public int getTimeLenght() {
  29. return timeLenght;
  30. }
  31. public void setTimeLenght(int timeLenght) {
  32. this.timeLenght = timeLenght;
  33. }
  34. @Override
  35. public String toString() {
  36. return "Video [id=" + id + ", title=" + title + ", timeLenght="
  37. + timeLenght + "]";
  38. }
  39. }

布局

  1. main.xml
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical" >
  7. <ListView
  8. android:id="@+id/listViewID"
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content" >
  11. </ListView>
  12. </LinearLayout>

Item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="horizontal" >
  6. <TextView
  7. android:id="@+id/titleID"
  8. android:layout_width="200dp"
  9. android:layout_height="wrap_content" />
  10. <TextView
  11. android:id="@+id/timelengthID"
  12. android:layout_width="fill_parent"
  13. android:layout_height="wrap_content" />
  14. </LinearLayout>
Copyright © Linux教程網 All Rights Reserved