简体   繁体   English

使用sax在android中解析xml数据

[英]parsing xml data in android using sax

I have to develop one android xml parsing using sax app. 我必须使用sax应用程序开发一个android xml解析。

Here i displayed the category-name and article title for belonging category on single listview...its done well.. 在这里,我在单个listview上显示了所属类别的类别名称和文章标题...做得很好。

But my requirement is category name is display on gridview and article title is display on horizontal listview for below the corresponding category. 但我的要求是,对应名称下方的类别名称显示在gridview上,文章标题显示在水平列表视图中。

Here i have to use below code means am getting following error: 在这里,我必须使用以下代码表示出现以下错误:

The method setAdapter(ListAdapter) in the type HorizontalListView is not applicable for the arguments (String) Horizo​​ntalListView类型的方法setAdapter(ListAdapter)不适用于参数(字符串)

Laptop.java: Laptop.java:

public class Laptop {
   private String model;
private String brand;
public String getModel() {
    return model;
}
public void setModel(String model) {
    this.model = model;
}

public String getBrand() {
    return brand;
}
public void setBrand(String brand) {
    this.brand = brand;
}}

In SaxXMLHandler.java SaxXMLHandler.java中

 public void startElement(String uri, String localName, String qName,
        Attributes attributes) throws SAXException {
    // reset
    tempVal = "";
    if (qName.equalsIgnoreCase("Category")) {
        // create a new instance of Laptop
        laptop = new Laptop();
        laptop.setBrand(attributes.getValue("name"));
    }
    else  if (qName.equalsIgnoreCase("article")) {
        // create a new instance of Laptop
        article = new Laptop();
        article.setModel(attributes.getValue("title"));
    } 

In CustomListViewAdapter.java CustomListViewAdapter.java中

    public class CustomListViewAdapter extends ArrayAdapter<Laptop> {
     Activity context;
     List<Laptop> laptops;

     public CustomListViewAdapter(Context context2, List<Laptop> laptops) {
     super(context2, R.layout.list_item, laptops);
    this.context = (Activity) context2;
    this.laptops = laptops;
}

/*private view holder class*/
private class ViewHolder {
    ImageView imageView;
    HorizontalListView txtModel;

    TextView txtBrand;
    TextView txtPrice;
}

public Laptop getItem(int position) {
    return laptops.get(position);
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    LayoutInflater inflater = context.getLayoutInflater();

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.list_item, null);
        holder = new ViewHolder();
        holder.txtModel = (HorizontalListView) convertView.findViewById(R.id.model);

        holder.txtBrand = (TextView) convertView.findViewById(R.id.brand);
      //  holder.txtPrice = (TextView) convertView.findViewById(R.id.price);
       // holder.imageView = (ImageView) convertView.findViewById(R.id.thumbnail);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    Laptop laptop = (Laptop) getItem(position);
    // holder.txtModel.setText(laptop.getModel());
    holder.txtBrand.setText(laptop.getBrand());
   // holder.imageView.setImageBitmap(laptop.getImageBitmap());
   // holder.txtPrice.setText(laptop.getPrice() + "");

  holder.txtModel.setAdapter(laptop.getModel());
    return convertView;
}}

In HorizontalListView.java Horizo​​ntalListView.java中

public void setAdapter(ListAdapter adapter) {
    if(mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mDataObserver);
   }
    mAdapter = adapter;
     mAdapter.registerDataSetObserver(mDataObserver);
    reset();
   }

am getting the above error in the below line: 在下面的行中收到上述错误:

holder.txtModel.setAdapter(laptop.getModel()); holder.txtModel.setAdapter(laptop.getModel());

How can i resolve these ??? 我该如何解决这些问题? How can i get the article title on horizontal listview for below the corresponding category... 我如何在相应类别下的水平列表视图中获取文章标题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM