1

模拟器的图片

上图只是添加两个值并在下面的文本视图中显示结果。但我需要在下一个屏幕上的 tabhost 的第一个选项卡(即 Tab_1)上显示该答案。这该怎么做?

.java 类

 public class Demo_webserviceActivity extends Activity
{
/** Called when the activity is first created. */

   private static String NAMESPACE = "http://tempuri.org/";
   private static String METHOD_NAME = "FahrenheitToCelsius";
   private static String SOAP_ACTION = "http://tempuri.org/FahrenheitToCelsius";
   private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";

   Button btnFar;
   EditText txtFar;

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

   btnFar = (Button)findViewById(R.id.btnFar);

   txtFar = (EditText)findViewById(R.id.txtFar);

   btnFar.setOnClickListener(new View.OnClickListener()
   {
   public void onClick(View v)
   {

       String b;

     //Initialize soap request + add parameters
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

     //Use this to add parameters
     request.addProperty("Fahrenheit",txtFar.getText().toString());

     //Declare the version of the SOAP request
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

     envelope.setOutputSoapObject(request);
     envelope.dotNet = true;

     try 
     {
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

         //this is the actual part that will call the webservice
         androidHttpTransport.call(SOAP_ACTION, envelope);

         // Get the SoapResult from the envelope body.

         SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

         if(result != null)
         {
          //Get the first property and change the label text

            b = result.toString();

            Intent i = new Intent(getApplicationContext(),Activity2.class);
            i.putExtra("gotonextpage", b.toString());
            startActivity(i);
          }

         else
         {
           Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_SHORT).show();
         }
    }
    catch (Exception e)
    {
       e.printStackTrace();
       }
     }
   });
   }
} 

注意:这个源实际上是从 android 使用 web 服务并通过 SOAP 方法显示结果

非常感谢。

4

1 回答 1

0

您可以使用共享首选项来存储值,然后您可以在项目的任何活动中访问它:

按照这个链接

于 2012-06-14T12:29:07.237 回答