在我的应用程序中,我想在单击按钮(位于第一个屏幕中)时调用 Web 服务。在第一个屏幕中,我将输入一个输入。基于该输入值,Web 服务必须发挥作用。单击按钮后,我调用了一个新意图并调用了 Web 服务,但是我如何将值从 1 个屏幕传递到其他屏幕。
我的代码:
这是按钮点击(第一个屏幕)
public void onClick(View v)
{
// TODO Auto-generated method stub
// EditText medit;
// EditText medit=(EditText)findViewById(R.id.editText1);
Intent myIntent = new Intent(v.getContext(), dispaly.class);
startActivity(myIntent);
}
这是网络服务(点击按钮后)
medit=(EditText)findViewById(R.id.editText1);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String weight = medit.getText().toString();
String fromUnit = "Grams";
String toUnit = "Kilograms";
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
// weightProp.setValue(medit.toString());
weightProp.setType(double.class);
request.addProperty(weightProp);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromUnit");
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
request.addProperty(fromProp);
PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToUnit");
toProp.setValue(toUnit);
toProp.setType(String.class);
request.addProperty(toProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
TextView tv = new TextView(this);
tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
setContentView(tv);
}
catch (Exception e)
{
e.printStackTrace();
}
}.