如何在android中使用soap web服务时使用数组列表

时间:2014-07-09 04:58:29

标签: android arrays soap arraylist

我正在使用soap web服务使用android获取MySQL服务器中的数据,我将这些数据拆分并存储在数组中,现在我尝试转换数组列表。我试过它不起作用... 你能告诉我怎么做那个? 提前致谢

public class Month extends Activity {

    private static final String SOAP_ACTION = "http://tempuri.org/Monthamount";

    private static final String OPERATION_NAME = "Monthamount";

    private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

   private static final String SOAP_ADDRESS = "http://220.226.170.5/service.asmx?WSDL";

   boolean timeoutexcep=false,httpexcep=false,generalexcep=false;

    TextView m,ma,a,aa,e,ea,d,da,hk,hka,h,ha,ta,taa,nrf,session,amount,o,oa;
    EditText edata;
    ImageView button;
    String month;
    HttpTransportSE httpTransport;
    SoapSerializationEnvelope envelope;
    Object response;
    //SoapPrimitive s;
    ProgressDialog progress;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.month);

        progress = new ProgressDialog(Month.this);
        button = (ImageView) findViewById(R.id.imageView1);
        m = (TextView) findViewById(R.id.m);
        ma = (TextView) findViewById(R.id.ma);

        a = (TextView) findViewById(R.id.a);
        aa = (TextView) findViewById(R.id.aa);

        e = (TextView) findViewById(R.id.e);
        ea = (TextView) findViewById(R.id.ea);

        d = (TextView) findViewById(R.id.d);
        da = (TextView) findViewById(R.id.da);

        hk = (TextView) findViewById(R.id.hk);
        hka = (TextView) findViewById(R.id.hka);

        h = (TextView) findViewById(R.id.h);
        ha = (TextView) findViewById(R.id.ha);

        ta = (TextView) findViewById(R.id.ta);
        taa = (TextView) findViewById(R.id.taa);

        /*o = (TextView) findViewById(R.id.o);
        oa = (TextView) findViewById(R.id.oa);*/


        nrf = (TextView) findViewById(R.id.nrf);

       session = (TextView) findViewById(R.id.textView1);

        amount = (TextView) findViewById(R.id.textView2);

        edata = (EditText) findViewById(R.id.editText1);



        button.setOnClickListener(new OnClickListener() {


            public void onClick(View v) {



                session.setVisibility(View.VISIBLE); 
                amount.setVisibility(View.VISIBLE);
                m.setVisibility(View.VISIBLE);
                ma.setVisibility(View.VISIBLE);
                a.setVisibility(View.VISIBLE);
                aa.setVisibility(View.VISIBLE);
                e.setVisibility(View.VISIBLE);
                ea.setVisibility(View.VISIBLE);
                d.setVisibility(View.VISIBLE);
                da.setVisibility(View.VISIBLE);
                h.setVisibility(View.VISIBLE);
                ha.setVisibility(View.VISIBLE);
                hk.setVisibility(View.VISIBLE);
                hka.setVisibility(View.VISIBLE);
                ta.setVisibility(View.VISIBLE);
                taa.setVisibility(View.VISIBLE);
                /*o.setVisibility(View.VISIBLE);
                oa.setVisibility(View.VISIBLE);*/




                SoapObject request=new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

                month= edata.getText().toString();



                request.addProperty("Month", month);


                envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet=true;
                envelope.setOutputSoapObject(request);

                httpTransport = new HttpTransportSE(SOAP_ADDRESS);

                try {

                     serviceCall();

                } catch (Exception exception) {

                    /*tvData1.setText(exception.toString()
                        + " Or No Records Found!");*/

                }

            }
        });

            }


    void serviceCall() {
        progress.setMessage("Please wait...");
        progress.show();

        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                try {

                    httpTransport.call(SOAP_ACTION, envelope);
                    response = envelope.getResponse();
                }
                    catch(SocketTimeoutException e){
                        timeoutexcep=true;
                        e.printStackTrace();
                    }

                    catch(ConnectException e){
                        httpexcep=true;
                        e.printStackTrace();
                        }
                        catch (Exception e) {
                        generalexcep=true;
                        e.printStackTrace();
                        }
                return null;
            }



            @Override
            protected void onPostExecute(Void result) {
                String str = "";

                if(timeoutexcep){
                    Toast.makeText(Month.this, "Unable to connect to server, Please try again later",Toast.LENGTH_LONG).show();
                    }
                else if(httpexcep){
                    Toast.makeText(Month.this, "Check Your Internet Connection",Toast.LENGTH_LONG).show();
                    }
                else if(generalexcep){
                    Toast.makeText(Month.this, "Please try again later",Toast.LENGTH_LONG).show();
                    }
                else {

                    }
                    timeoutexcep=false;httpexcep=false;generalexcep=false;
                if (progress != null)
                    progress.dismiss();
                if (response != null) {


                    // ArrayList<String> al = new ArrayList<String>()(Arrays.asList(commaSeparated.split(",")));  
                    // al=(ArrayList<Stirng>) response;
                     //toString().split(";"); 
                    String resultArr[] = response.toString().split(";");



                    session.setVisibility(View.VISIBLE); 
                    amount.setVisibility(View.VISIBLE);

                    m.setVisibility(View.VISIBLE);

                    a.setVisibility(View.VISIBLE);

                    e.setVisibility(View.VISIBLE);

                    d.setVisibility(View.VISIBLE);

                    h.setVisibility(View.VISIBLE);

                    hk.setVisibility(View.VISIBLE);

                    //o.setVisibility(View.VISIBLE);

                    m.setText(resultArr[1].split("-")[0]);
                     ma.setText(resultArr[1] .split("-")[1]);


                     a.setText(resultArr[4].split("-")[0]);
                    aa.setText(resultArr[4].split("-")[1]);

                    e.setText(resultArr[0].split("-")[0]);
                     ea.setText(resultArr[0].split("-")[1]);

                     d.setText(resultArr[5].split("-")[0]);
                     da.setText(resultArr[5].split("-")[1]);

                     hk.setText(resultArr[2].split("-")[0]);
                     hka.setText(resultArr[2].split("-")[1]);

                     h.setText(resultArr[3].split("-")[0]);
                     ha.setText(resultArr[3].split("-")[1]);




                    String a1,b,c,d1,e1,f,g;

                    double res;
                    a1 = ma.getText().toString();
                    b = aa.getText().toString(); 
                    c=ea.getText().toString();
                    d1=da.getText().toString();
                    e1=hka.getText().toString();
                    f=ha.getText().toString();
                    //g=oa.getText().toString();

                    res = Double.parseDouble(a1)+Double.parseDouble(b)+Double.parseDouble(c)+Double.parseDouble(d1)+Double.parseDouble(e1)+Double.parseDouble(f);/*+Double.parseDouble(g);*/


                    DecimalFormat format = new DecimalFormat("##.##");
                    String formattedText = format.format(res);
                    taa.setText(formattedText);


                }
                else 

                    if(response==null)
                    {
                        nrf.setText("No Records Found!");
                        m.setText("");
                        ma.setText("");
                        a.setText("");
                        aa.setText("");
                        e.setText("");
                        ea.setText("");
                        d.setText("");
                        da.setText("");
                        hk.setText("");
                        hka.setText("");
                        h.setText("");
                        ha.setText("");
                        ta.setText("");
                        taa.setText("");

                    }




                                        }

        }.execute();

    }
}

如果我给出一个特定的日期,那么输出将是这样的。

<string xmlns="http://tempuri.org/">
Evening-879852.17;Morning-1784588.51;Housekeeping-566652.06;Home-9585.99;Afternoon-4213060.58;Night-1768560.44;
</string>

如果我将它存储在数组中,它会显示答案。有时晚上和其他人不会出现在其他日期。所以,数组值递减,应用程序将强制关闭

避免使用我试过的数组列表

提前致谢

0 个答案:

没有答案