0

我已经编写了一个表格布局来自动从 Web 服务填充值,但我是 java 和 android 的新手并写了这个。我想将 sax 解析器中的 vlaues 添加到 tablerow。请帮助我如何将其添加到表格布局中。我已经给出了下面的文件。

在此处输入图像描述

表格布局

public class TablePage extends Activity {
ArrayList<Bookdetails>bookno=new ArrayList<Bookdetails>();
ArrayList<Bookdetails>booktitle1=new ArrayList<Bookdetails>();
 private final String NAMESPACE = "http://www.webserviceX.NET/";
 private final String URL = "http://www.webservicex.net/BibleWebservice.asmx";
 private final String SOAP_ACTION = "http://www.webserviceX.NET/GetBookTitles";
 private final String METHOD_NAME = "GetBookTitles";
 TableLayout country_table; 
 TableRow countrydet;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_table_page);
    country_table=(TableLayout)findViewById(R.id.Employee_Table);;

     new service().execute();

}

public void createtable()
{


}
private class service extends AsyncTask<Void, Void, ArrayList<Bookdetails>>{
    saxparser sax=new saxparser();
    @Override
    protected ArrayList<Bookdetails> doInBackground(Void... params) {

        // TODO Auto-generated method stub
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;
        try{
            HttpTransportSE androidHttpTransport=new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            //String resdump=androidHttpTransport.responseDump.toString();
            //System.out.println(resdump);
            SoapPrimitive result=(SoapPrimitive)envelope.getResponse();


            //sax(result.toString());
            Xml.parse(result.toString(),sax);

        }
        catch(Exception e){
            e.printStackTrace();
        }
        return sax.getdetails();
    }

    protected void onPostExecute(ArrayList<Bookdetails> details)
    {

         for(int i=0;i<details.size();i++)
         {

         }




    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_table_page, menu);
    return true;
}

}

saxparser.java

public class saxparser extends DefaultHandler{
TableLayout book_table;
TableRow bookrow;

Boolean currentElement=false;
String currentValue=null;
public static Bookdetails bookdetails = null;
String data;

ArrayList<Bookdetails> datas=new ArrayList<Bookdetails>();


public void startElement(String uri, String localName, String Name,
        Attributes attributes) throws SAXException {
    currentElement=true;
    if(localName.equals("NewDataSet")){
        bookdetails=new Bookdetails();

    }
    else if(localName.equals("Table")){
        String bookno=attributes.getValue("Book");


        String booktitle=attributes.getValue("BookTitle");


        }

}
public void characters(char[] ch,int start,int length ) throws SAXException{
    if(currentElement){
        currentValue=new String(ch,start,length);
                    currentElement=false;
    }
}
public void endElement(String uri, String localName, String qName)
        throws SAXException {
    if(localName.equalsIgnoreCase("Book")){
        bookdetails.setBookno(currentValue);
    }else if(localName.equalsIgnoreCase("BookTitle")){
        bookdetails.setBooktitle(currentValue);

    }else if(localName.equalsIgnoreCase("Table")){
        datas.add(bookdetails);


    }


}
public ArrayList<Bookdetails> getdetails()
{
    return datas;
}
// System.out.println(bookno.size());

Bookdetails.java(Getter Setter 方法)

package com.example.tablepagination;



import java.util.ArrayList;

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

public String bookno;
public String getBookno() {
    return bookno;
}
public void setBookno(String bookno) {
    this.bookno = bookno;
}
public String getBooktitle() {
    return booktitle;
}
public void setBooktitle(String booktitle) {
    this.booktitle = booktitle;
}
public String booktitle;



}

我已经为 sax 解析器使用了 getter setter 方法。如何将 arraylist 字符串添加到我的表行。谁能告诉我方法

4

1 回答 1

0

查看有关 ListView 的 android 指南。 您应该使用带有适配器的 ListView 来显示来自 SaxParser 的元素。

于 2012-11-23T10:17:23.013 回答