开发者

How can I read xml data from internet in Android ListView?

How can i read the categories education and work in a android ListView? Now on clicking any category its childs Google,IBM,etc. are shown in a new s开发者_高级运维creen. How can it be implemented?


You have to follow the following steps to get your work done

Step-1 You need to parse the xml. see http://xmlpull.org/v1/src/java/samples/MyXmlPullApp.java

Step-2 Create a bean class for Category. means all the category related data will be stored in that bean class

Step-3 Create an arraylist of that bean class

Step-4 Create a list view using that arraylist ( the list view will display only name of categories)

Step-5 Implement on itemclik listener on the list view. get the position. retrieve the data pass to the intent call second activity

Step-6 In the second activity create a listview and display the data whatever is passed by first activity

NetworkBean

public class NetWorkBean {
    String name;
    int id;
    NetWorkBean(String name, int id){
        this.name = name;
        this.id = id;
    }
    public String getNetWorkName(){
        return name;
    }
    public int getNetWorkId(){
        return id;
    }
}

CategoryBean

import java.util.ArrayList;


public class CategoryBean {
    String name;
    ArrayList<NetWorkBean> networkList;
    public CategoryBean(String name, ArrayList<NetWorkBean> networkList){
        this.name = name;
        this.networkList = networkList;
    }
    public String getNetWorkName(){
        return name;
    }
    public ArrayList<NetWorkBean> getNetWorkList(){
        return networkList;
    }


}


you can see this

http://www.androidpeople.com/android-xml-parsing-tutorial-%E2%80%93-using-domparser

After parsing the data set it to the list view.Then in the list onclick event implement

what you need.You can call an another activity and sending the corresponding address in a

bundle then retrieving that on the activity you can show in webview

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜