我已经编写了一个表格布局来自动填充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字符串添加到我的表行。有人可以告诉我方法