android中通过url进行sax解析

发布于 2024-11-02 03:56:17 字数 15751 浏览 0 评论 0原文

我正在尝试解析 Android 中的 URL,但它给出了除类别之外的空值。你能帮我解决它吗?

//my main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>

//sitelist.java
package com.androidpeople.xml.parsing;

import java.util.ArrayList;

/** Contains getter and setter method for varialbles  */
public class SitesList {

    /** Variables */
    private ArrayList<String> Product = new ArrayList<String>();
    private ArrayList<String> Products = new ArrayList<String>();
    private ArrayList<String> PriceSet = new ArrayList<String>();
    private ArrayList<String> categoryId = new ArrayList<String>();
    private ArrayList<String> id= new ArrayList<String>();
    private ArrayList<String> title  = new ArrayList<String>();
    private ArrayList<String> description = new ArrayList<String>();
    private ArrayList<String> manufacturer = new ArrayList<String>();
    private ArrayList<String> url = new ArrayList<String>();
    private ArrayList<String> Image   = new ArrayList<String>();
    private ArrayList<String> relevancy = new ArrayList<String>();
    private ArrayList<String> minPrice  = new ArrayList<String>();
    private ArrayList<String> maxPrice    = new ArrayList<String>();
    private ArrayList<String> stores = new ArrayList<String>();


    /** In Setter method default it will return arraylist 
     *  change that to add  */

    public ArrayList<String> getProduct() {

        return this.Product;
    }

    public void setProduct(String Product) {
        this.Product.add(Product);
    }

    public ArrayList<String> getProducts() {
        return this.Products;
    }

    public void setProducts(String Products) {
        this.Products.add(Products);
    }


    public ArrayList<String> getPriceSet() {
        return PriceSet;
    }

    public void setPriceSet(String PriceSet) {
        this.PriceSet.add(PriceSet);
    }

    public void setcategoryId(String categoryId) {
        this.categoryId.add(categoryId);
    }
    public ArrayList<String> getcategoryId() {
        return categoryId;
    }
    public ArrayList<String> getid() {
        return id;
    }

    public void setid(String id) {
        this.id.add(id);
    }

    public ArrayList<String> gettitle() {
        return title;
    }

    public void settitle(String title) {
        this.title.add(title);
    }

    public ArrayList<String> getdescription() {
        return description;
    }

    public void setdescription(String description) {
        this.description.add(description);
    }
    public ArrayList<String> getmanufacturer() {
        return manufacturer;
    }

    public void setmanufacturer(String manufacturer) {
        this.manufacturer.add(manufacturer);
    }

    public ArrayList<String> geturl() {
        return url;
    }

    public void seturl(String url) {
        this.url.add(url);
    }

    public ArrayList<String> getImage() {
        return Image;
    }

    public void setImage(String Image) {
        this.Image.add(Image);
    }
    public ArrayList<String> getrelevancy() {
        return relevancy;
    }

    public void setrelevancy(String relevancy) {
        this.relevancy.add(relevancy);
    }

    public ArrayList<String> getminPrice() {
        return minPrice;
    }

    public void setminPrice(String minPrice) {
        this.minPrice.add(minPrice);
    }

    public ArrayList<String> getmaxPrice() {
        return maxPrice;
    }

    public void setmaxPrice(String maxPrice) {
        this.maxPrice.add(maxPrice);
    }
    public ArrayList<String> getstores() {
        return stores;
    }

    public void setstores(String stores) {
        this.stores.add(stores);
    }

    public void setWebsite(String currentValue) {
        // TODO Auto-generated method stub

    }  

}

//myxmlhandler.java

package com.androidpeople.xml.parsing;

import org.xml.sax.Attributes;


import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class MyXMLHandler extends DefaultHandler {

    Boolean currentElement = false;
    String currentValue = null;
    public static SitesList sitesList = null;

    public static SitesList getSitesList() {
        return sitesList;
    }

    public static void setSitesList(SitesList sitesList) {
        MyXMLHandler.sitesList = sitesList;
    }

    /** Called when tag starts ( ex:- <name>AndroidPeople</name> 
     * -- <name> )*/
    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {

        currentElement = true;

        if (localName.equals("ProductResponse"))
        {
            //** Start *//* 
            sitesList = new SitesList();
        } else if (localName.equals("Products")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("Products");
            System.out.println("Data"+attr);
            sitesList.setProducts(attr);
        }
        else if (localName.equals("PriceSet")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("PriceSet");
            System.out.println("Data"+attr);
            sitesList.setPriceSet(attr);
        }
        else if (localName.equals("Product")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("categoryId");
            System.out.println("Data"+attr);
            sitesList.setcategoryId(attr);

                    /** Get attribute value */
                    String attr1 = attributes.getValue("id");
                    System.out.println("Data"+attr);
                    sitesList.setid(attr);
        }else if (localName.equals("title")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("title");
            System.out.println("Data"+attr);
            sitesList.settitle(attr);


        }else if (localName.equals("description")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("description");
            System.out.println("Data"+attr);
            sitesList.setdescription(attr);


        }else if (localName.equals("manufacturer")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("manufacturer");
            System.out.println("Data"+attr);
            sitesList.setmanufacturer(attr);


        }else if (localName.equals("url")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("url");
            System.out.println("Data"+attr);
            sitesList.seturl(attr);


        }else if (localName.equals("Image")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("Image");
            System.out.println("Data"+attr);
            sitesList.setImage(attr);


        }else if (localName.equals("relevancy")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("relevancy");
            System.out.println("Data"+attr);
            sitesList.setrelevancy(attr);


        }else if (localName.equals("minPrice")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("minPrice");
            System.out.println("Data"+attr);
            sitesList.setminPrice(attr);


        }else if (localName.equals("maxPrice")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("maxPrice");
            System.out.println("Data"+attr);
            sitesList.setmaxPrice(attr);


        }else if (localName.equals("stores")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("stores");
            System.out.println("Data"+attr);
            sitesList.setstores(attr);


        }

    }

    /** Called when tag closing ( ex:- <name>AndroidPeople</name> 
     * -- </name> )*/
    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {

        currentElement = false;

        /** set value */ 
        if (localName.equalsIgnoreCase("title"))
            sitesList.settitle(currentValue);
        else if (localName.equalsIgnoreCase("description"))
            sitesList.setdescription(currentValue);

    }

    /** Called to get tag characters ( ex:- <name>AndroidPeople</name> 
     * -- to get AndroidPeople Character ) */
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

        if (currentElement) {
            currentValue = new String(ch, start, length);
            currentElement = false;
        }

    }

}

//myparsingexample.java
package com.androidpeople.xml.parsing;

import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class XMLParsingExample extends Activity {

    /** Create Object For SiteList Class */
    SitesList sitesList = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /** Create a new layout to display the view */
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(1);

        /** Create a new textview array to display the results */
        TextView Product[];
        TextView categoryId[];
        TextView id[];
        TextView title[];
        TextView description[];
        TextView manufacturer[];
        TextView url[];
        TextView Image[];
        TextView relevancy[];
        TextView minPrice[];
        TextView maxPrice[];
        TextView stores[];
        TextView Products[];
        TextView PriceSet[];


        try {

            /** Handling XML */
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();

            /** Send URL to parse XML Tags */
            URL sourceUrl = new URL(
                    "http://catalog.bizrate.com/services/catalog/v1/us/product?publisherId=50085&placementId=1&categoryId=1&keyword=ipod&productId=&productIdType=SZPID&merchantId=&minPrice=&maxPrice=&start=0&results=10&startOffers=0&resultsOffers=0&sort=relevancy_desc&brandId=&attFilter=&showAttributes=&showProductAttributes=&zipCode=&offersOnly=&biddedOnly=&minRelevancyScore=100&apiKey=58f536aa2fab110bbe0da501150bac1e");

            /** Create handler to handle XML Tags ( extends DefaultHandler ) */
            MyXMLHandler myXMLHandler = new MyXMLHandler();
            xr.setContentHandler(myXMLHandler);
            xr.parse(new InputSource(sourceUrl.openStream()));

        } catch (Exception e) {
            System.out.println("XML Pasing Excpetion = " + e);
        }

        /** Get result from MyXMLHandler SitlesList Object */
        sitesList = MyXMLHandler.sitesList;

        /** Assign textview array lenght by arraylist size */
        Product = new TextView[sitesList.getProduct().size()];
        categoryId = new TextView[sitesList.getcategoryId().size()];
        Products = new TextView[sitesList.getProducts().size()];
        PriceSet = new TextView[sitesList.getPriceSet().size()];
        id = new TextView[sitesList.getid().size()];
        title = new TextView[sitesList.gettitle().size()];
        manufacturer = new TextView[sitesList.getmanufacturer().size()];
        description = new TextView[sitesList.getdescription().size()];
        Image = new TextView[sitesList.getImage().size()];
        relevancy = new TextView[sitesList.getrelevancy().size()];
        minPrice = new TextView[sitesList.getminPrice().size()];
        maxPrice = new TextView[sitesList.getmaxPrice().size()];
        stores = new TextView[sitesList.getstores().size()];
        url = new TextView[sitesList.geturl().size()];

        /** Set the result text in textview and add it to layout */
        for (int i = 0; i < sitesList.getProduct().size(); i++) {
            Product[i] = new TextView(this);
            Product[i].setText("Products = "+sitesList.getProducts().get(i));
            Products[i] = new TextView(this);
            Products[i].setText("Products = "+sitesList.getProducts().get(i));
            PriceSet[i] = new TextView(this);
            PriceSet[i].setText("PriceSet = "+sitesList.getPriceSet().get(i));
            categoryId[i] = new TextView(this);
            categoryId[i].setText("categoryId = "+sitesList.getcategoryId().get(i));
            id[i] = new TextView(this);
            id[i].setText(" id = "+sitesList.getid().get(i));
            title[i] = new TextView(this);
            title[i].setText("title = "+sitesList.gettitle().get(i));
            description[i] = new TextView(this);
            description[i].setText("description = "+sitesList.getdescription().get(i));
            manufacturer[i] = new TextView(this);
            manufacturer[i].setText(" manufacturer = "+sitesList.getmanufacturer().get(i));
            url[i] = new TextView(this);
            url[i].setText("url = "+sitesList.geturl().get(i));
            Image[i] = new TextView(this);
            Image[i].setText("Image = "+sitesList.getImage().get(i));
            relevancy[i] = new TextView(this);
            relevancy[i].setText(" relevancy = "+sitesList.getrelevancy().get(i));
            minPrice[i] = new TextView(this);
            minPrice[i].setText("minPrice = "+sitesList.getminPrice().get(i));
            maxPrice[i] = new TextView(this);
            maxPrice[i].setText("maxPrice = "+sitesList.getmaxPrice().get(i));
            stores[i] = new TextView(this);
            stores[i].setText(" id = "+sitesList.getstores().get(i));

            layout.addView(Product[i]);
            layout.addView(categoryId[i]);
            layout.addView(id[i]);
            layout.addView(title[i]);
            layout.addView(description[i]);
            layout.addView(manufacturer[i]);
            layout.addView(url[i]);
            layout.addView(Image[i]);
            layout.addView(relevancy[i]);
            layout.addView(minPrice[i]);
            layout.addView(maxPrice[i]);
            layout.addView(stores[i]);
            layout.addView(description[i]);
        }

        /** Set the layout view to display */
        setContentView(layout);

    }
}

该值也不存在于 ddms 中吗?

I am trying to parse a URL in Android but it gives a null value except category. Can you help me fix it?

//my main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>

//sitelist.java
package com.androidpeople.xml.parsing;

import java.util.ArrayList;

/** Contains getter and setter method for varialbles  */
public class SitesList {

    /** Variables */
    private ArrayList<String> Product = new ArrayList<String>();
    private ArrayList<String> Products = new ArrayList<String>();
    private ArrayList<String> PriceSet = new ArrayList<String>();
    private ArrayList<String> categoryId = new ArrayList<String>();
    private ArrayList<String> id= new ArrayList<String>();
    private ArrayList<String> title  = new ArrayList<String>();
    private ArrayList<String> description = new ArrayList<String>();
    private ArrayList<String> manufacturer = new ArrayList<String>();
    private ArrayList<String> url = new ArrayList<String>();
    private ArrayList<String> Image   = new ArrayList<String>();
    private ArrayList<String> relevancy = new ArrayList<String>();
    private ArrayList<String> minPrice  = new ArrayList<String>();
    private ArrayList<String> maxPrice    = new ArrayList<String>();
    private ArrayList<String> stores = new ArrayList<String>();


    /** In Setter method default it will return arraylist 
     *  change that to add  */

    public ArrayList<String> getProduct() {

        return this.Product;
    }

    public void setProduct(String Product) {
        this.Product.add(Product);
    }

    public ArrayList<String> getProducts() {
        return this.Products;
    }

    public void setProducts(String Products) {
        this.Products.add(Products);
    }


    public ArrayList<String> getPriceSet() {
        return PriceSet;
    }

    public void setPriceSet(String PriceSet) {
        this.PriceSet.add(PriceSet);
    }

    public void setcategoryId(String categoryId) {
        this.categoryId.add(categoryId);
    }
    public ArrayList<String> getcategoryId() {
        return categoryId;
    }
    public ArrayList<String> getid() {
        return id;
    }

    public void setid(String id) {
        this.id.add(id);
    }

    public ArrayList<String> gettitle() {
        return title;
    }

    public void settitle(String title) {
        this.title.add(title);
    }

    public ArrayList<String> getdescription() {
        return description;
    }

    public void setdescription(String description) {
        this.description.add(description);
    }
    public ArrayList<String> getmanufacturer() {
        return manufacturer;
    }

    public void setmanufacturer(String manufacturer) {
        this.manufacturer.add(manufacturer);
    }

    public ArrayList<String> geturl() {
        return url;
    }

    public void seturl(String url) {
        this.url.add(url);
    }

    public ArrayList<String> getImage() {
        return Image;
    }

    public void setImage(String Image) {
        this.Image.add(Image);
    }
    public ArrayList<String> getrelevancy() {
        return relevancy;
    }

    public void setrelevancy(String relevancy) {
        this.relevancy.add(relevancy);
    }

    public ArrayList<String> getminPrice() {
        return minPrice;
    }

    public void setminPrice(String minPrice) {
        this.minPrice.add(minPrice);
    }

    public ArrayList<String> getmaxPrice() {
        return maxPrice;
    }

    public void setmaxPrice(String maxPrice) {
        this.maxPrice.add(maxPrice);
    }
    public ArrayList<String> getstores() {
        return stores;
    }

    public void setstores(String stores) {
        this.stores.add(stores);
    }

    public void setWebsite(String currentValue) {
        // TODO Auto-generated method stub

    }  

}

//myxmlhandler.java

package com.androidpeople.xml.parsing;

import org.xml.sax.Attributes;


import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class MyXMLHandler extends DefaultHandler {

    Boolean currentElement = false;
    String currentValue = null;
    public static SitesList sitesList = null;

    public static SitesList getSitesList() {
        return sitesList;
    }

    public static void setSitesList(SitesList sitesList) {
        MyXMLHandler.sitesList = sitesList;
    }

    /** Called when tag starts ( ex:- <name>AndroidPeople</name> 
     * -- <name> )*/
    @Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {

        currentElement = true;

        if (localName.equals("ProductResponse"))
        {
            //** Start *//* 
            sitesList = new SitesList();
        } else if (localName.equals("Products")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("Products");
            System.out.println("Data"+attr);
            sitesList.setProducts(attr);
        }
        else if (localName.equals("PriceSet")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("PriceSet");
            System.out.println("Data"+attr);
            sitesList.setPriceSet(attr);
        }
        else if (localName.equals("Product")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("categoryId");
            System.out.println("Data"+attr);
            sitesList.setcategoryId(attr);

                    /** Get attribute value */
                    String attr1 = attributes.getValue("id");
                    System.out.println("Data"+attr);
                    sitesList.setid(attr);
        }else if (localName.equals("title")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("title");
            System.out.println("Data"+attr);
            sitesList.settitle(attr);


        }else if (localName.equals("description")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("description");
            System.out.println("Data"+attr);
            sitesList.setdescription(attr);


        }else if (localName.equals("manufacturer")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("manufacturer");
            System.out.println("Data"+attr);
            sitesList.setmanufacturer(attr);


        }else if (localName.equals("url")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("url");
            System.out.println("Data"+attr);
            sitesList.seturl(attr);


        }else if (localName.equals("Image")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("Image");
            System.out.println("Data"+attr);
            sitesList.setImage(attr);


        }else if (localName.equals("relevancy")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("relevancy");
            System.out.println("Data"+attr);
            sitesList.setrelevancy(attr);


        }else if (localName.equals("minPrice")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("minPrice");
            System.out.println("Data"+attr);
            sitesList.setminPrice(attr);


        }else if (localName.equals("maxPrice")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("maxPrice");
            System.out.println("Data"+attr);
            sitesList.setmaxPrice(attr);


        }else if (localName.equals("stores")) {
            sitesList = new SitesList();
            /** Get attribute value */
            String attr = attributes.getValue("stores");
            System.out.println("Data"+attr);
            sitesList.setstores(attr);


        }

    }

    /** Called when tag closing ( ex:- <name>AndroidPeople</name> 
     * -- </name> )*/
    @Override
    public void endElement(String uri, String localName, String qName)
            throws SAXException {

        currentElement = false;

        /** set value */ 
        if (localName.equalsIgnoreCase("title"))
            sitesList.settitle(currentValue);
        else if (localName.equalsIgnoreCase("description"))
            sitesList.setdescription(currentValue);

    }

    /** Called to get tag characters ( ex:- <name>AndroidPeople</name> 
     * -- to get AndroidPeople Character ) */
    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {

        if (currentElement) {
            currentValue = new String(ch, start, length);
            currentElement = false;
        }

    }

}

//myparsingexample.java
package com.androidpeople.xml.parsing;

import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class XMLParsingExample extends Activity {

    /** Create Object For SiteList Class */
    SitesList sitesList = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /** Create a new layout to display the view */
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(1);

        /** Create a new textview array to display the results */
        TextView Product[];
        TextView categoryId[];
        TextView id[];
        TextView title[];
        TextView description[];
        TextView manufacturer[];
        TextView url[];
        TextView Image[];
        TextView relevancy[];
        TextView minPrice[];
        TextView maxPrice[];
        TextView stores[];
        TextView Products[];
        TextView PriceSet[];


        try {

            /** Handling XML */
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();

            /** Send URL to parse XML Tags */
            URL sourceUrl = new URL(
                    "http://catalog.bizrate.com/services/catalog/v1/us/product?publisherId=50085&placementId=1&categoryId=1&keyword=ipod&productId=&productIdType=SZPID&merchantId=&minPrice=&maxPrice=&start=0&results=10&startOffers=0&resultsOffers=0&sort=relevancy_desc&brandId=&attFilter=&showAttributes=&showProductAttributes=&zipCode=&offersOnly=&biddedOnly=&minRelevancyScore=100&apiKey=58f536aa2fab110bbe0da501150bac1e");

            /** Create handler to handle XML Tags ( extends DefaultHandler ) */
            MyXMLHandler myXMLHandler = new MyXMLHandler();
            xr.setContentHandler(myXMLHandler);
            xr.parse(new InputSource(sourceUrl.openStream()));

        } catch (Exception e) {
            System.out.println("XML Pasing Excpetion = " + e);
        }

        /** Get result from MyXMLHandler SitlesList Object */
        sitesList = MyXMLHandler.sitesList;

        /** Assign textview array lenght by arraylist size */
        Product = new TextView[sitesList.getProduct().size()];
        categoryId = new TextView[sitesList.getcategoryId().size()];
        Products = new TextView[sitesList.getProducts().size()];
        PriceSet = new TextView[sitesList.getPriceSet().size()];
        id = new TextView[sitesList.getid().size()];
        title = new TextView[sitesList.gettitle().size()];
        manufacturer = new TextView[sitesList.getmanufacturer().size()];
        description = new TextView[sitesList.getdescription().size()];
        Image = new TextView[sitesList.getImage().size()];
        relevancy = new TextView[sitesList.getrelevancy().size()];
        minPrice = new TextView[sitesList.getminPrice().size()];
        maxPrice = new TextView[sitesList.getmaxPrice().size()];
        stores = new TextView[sitesList.getstores().size()];
        url = new TextView[sitesList.geturl().size()];

        /** Set the result text in textview and add it to layout */
        for (int i = 0; i < sitesList.getProduct().size(); i++) {
            Product[i] = new TextView(this);
            Product[i].setText("Products = "+sitesList.getProducts().get(i));
            Products[i] = new TextView(this);
            Products[i].setText("Products = "+sitesList.getProducts().get(i));
            PriceSet[i] = new TextView(this);
            PriceSet[i].setText("PriceSet = "+sitesList.getPriceSet().get(i));
            categoryId[i] = new TextView(this);
            categoryId[i].setText("categoryId = "+sitesList.getcategoryId().get(i));
            id[i] = new TextView(this);
            id[i].setText(" id = "+sitesList.getid().get(i));
            title[i] = new TextView(this);
            title[i].setText("title = "+sitesList.gettitle().get(i));
            description[i] = new TextView(this);
            description[i].setText("description = "+sitesList.getdescription().get(i));
            manufacturer[i] = new TextView(this);
            manufacturer[i].setText(" manufacturer = "+sitesList.getmanufacturer().get(i));
            url[i] = new TextView(this);
            url[i].setText("url = "+sitesList.geturl().get(i));
            Image[i] = new TextView(this);
            Image[i].setText("Image = "+sitesList.getImage().get(i));
            relevancy[i] = new TextView(this);
            relevancy[i].setText(" relevancy = "+sitesList.getrelevancy().get(i));
            minPrice[i] = new TextView(this);
            minPrice[i].setText("minPrice = "+sitesList.getminPrice().get(i));
            maxPrice[i] = new TextView(this);
            maxPrice[i].setText("maxPrice = "+sitesList.getmaxPrice().get(i));
            stores[i] = new TextView(this);
            stores[i].setText(" id = "+sitesList.getstores().get(i));

            layout.addView(Product[i]);
            layout.addView(categoryId[i]);
            layout.addView(id[i]);
            layout.addView(title[i]);
            layout.addView(description[i]);
            layout.addView(manufacturer[i]);
            layout.addView(url[i]);
            layout.addView(Image[i]);
            layout.addView(relevancy[i]);
            layout.addView(minPrice[i]);
            layout.addView(maxPrice[i]);
            layout.addView(stores[i]);
            layout.addView(description[i]);
        }

        /** Set the layout view to display */
        setContentView(layout);

    }
}

The value is not coming in ddms also?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2024-11-09 03:56:17

看看这个答案:解析 XML

一篇非常好的文章,详细解释了两种方法的 XML 解析。

check this answer out: Parsing XML

Its a very nice post, explains XML parsing with two approaches, in detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文