使用XML解析器表分页表布局Web服务 [英] Table pagination Table layout Web Service using XML parser

查看:155
本文介绍了使用XML解析器表分页表布局Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个表格布局从Web服务自动填充值,但我是新手Java和Android和写了这一点。我想补充的SAX解析器来tablerow.Please了可用的参数帮助我如何将它添加到表格的布局。我给下面的文件。

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.

表布局

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

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(消气setter方法​​)

} 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;



}

我用的getter setter方法​​SAX解析器。如何添加ArrayList中的字符串我的表行。谁能告诉我方法

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

推荐答案

看一看的有关的ListView android的指南。 您应该使用一个ListView一个适配器,可以显示从的SAXParser的元素。

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

这篇关于使用XML解析器表分页表布局Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆