Table pagination Table layout Web Service using XML parser

余生颓废 提交于 2019-12-04 06:44:12

问题


I have written a table layout to fill values automatically from web service but i am newbie for java and android and wrote this. I want to add the vlaues from the sax parser to tablerow.Please help me how to add it to table layout. i have given the files below.

Table Layout

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 Method)

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;



}

I have used the getter setter method for sax parser. How can i add the arraylist string to my table row. Can someone tell me the method


回答1:


Have a look at the android guide about ListView. You should use a ListView with an Adapter to display the elements from your SaxParser.



来源:https://stackoverflow.com/questions/13525822/table-pagination-table-layout-web-service-using-xml-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!