微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Android中使用kSOAP序列化double值

这是代码;

package com.SRS6;

import org.ksoap2.soapEnvelope;
import org.ksoap2.serialization.soapObject;
import org.ksoap2.serialization.soapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class result extends Activity {


    private static final String SOAP_ACTION = "http://tempuri.org/insertquizdata";      
    private static final String METHOD_NAME = "insertquizdata";      
    private static final String NAMESPACE = "http://tempuri.org/";      
    private static final String URL = "http://192.168.1.203/studentresponse/Service.asmx";


    TextView txtcorrect;
    TextView txtwrong;
    TextView txttime;
    TextView txttotal;
    TextView txtunattempted,tv;
    ImageView resimg;
//  TextView txttimer;

    String n1;
    int n2;
    double n3;

    DataBaseHelper data;



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

        data=new DataBaseHelper(this);

        //resimg=(ImageView)findViewById(R.id.img);
        tv=(TextView)findViewById(R.id.tv);
        txttotal=(TextView)findViewById(R.id.ua);
        txttotal.setTextColor(Color.BLACK);
        txtunattempted=(TextView)findViewById(R.id.ua1);
        txtunattempted.setTextColor(Color.BLACK);
        txtcorrect=(TextView)findViewById(R.id.correct);
        txtcorrect.setTextColor(Color.BLACK); 
        txtwrong=(TextView)findViewById(R.id.wrong);
        txtwrong.setTextColor(Color.BLACK);
        txttime=(TextView)findViewById(R.id.time3);
        txttime.setTextColor(Color.BLACK);
      //  txttimer=(TextView)findViewById(R.id.time4);
      //  txttimer.setTextColor(Color.BLACK);

        Bundle bundle = getIntent().getExtras(); 
        String stuname=bundle.getString("stuname");
        System.out.println("Student name:"+stuname);
        int tesid=bundle.getInt("testid",0);
        System.out.println("Test id:"+tesid);
        int value = bundle.getInt("correctcount", 0);
        int value1 = bundle.getInt("wrongcount", 0);
        int value2=bundle.getInt("Ques",0);
        int value3=bundle.getInt("unatt",0);

        double perce=(value*100)/value2;
        System.out.println("Percentage:"+perce);

        String time2 = bundle.getString("time");
        //String time3 = bundle.getString("timer");


        txttotal.setText(" "+value2+" No of questions");
        txtunattempted.setText(" "+value3+" Unattempted");
        txtcorrect.setText(" "+value+" right answers");
        txtwrong.setText(" "+value1+" wrong answers");
        txttime.setText(" "+time2);
       // txttimer.setText(" "+time3);


        data.Insertfinalresult(stuname, tesid, perce);
        getfinalresult();
       // call();


}

    public void call()
     { 
         try {


                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


                request.addProperty("strusername",n1);

                request.addProperty("inttestid",n2);

                request.addProperty("dblper",n3);


                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

                envelope.setoutputSoapObject(request);
                envelope.dotNet=true; 
                envelope.encodingStyle = SoapSerializationEnvelope.XSD;
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                androidHttpTransport.call(SOAP_ACTION, envelope);
               Toast.makeText(result.this, "Data posted successfully",Toast.LENGTH_SHORT).show();

         } 
            catch (Exception e)    
            { 
            tv.setText(e.getMessage());
            }  
     }

     public void getfinalresult()
     {
         Cursor c1=data.selectfinalresult();
            while(c1.movetoNext())
            {
                n1=c1.getString(0);
                n2=c1.getInt(1);
                n3=c1.getDouble(2);
                System.out.println("First:"+n1); 
                System.out.println("Second:"+n2);
                System.out.println("Third:"+n3);
                call();
            }
     }
}

请帮我知道如何使用kSOAP序列化double值.

解决方法:

需要手动编组Double和Date的数据类型.有一篇关于See Sharp Gears的文章可以帮助你解决这个问题.编组Double的链接是:Implementing KSOAP Marshal Interface.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐