有没有人遇到过这种情况,现在我正在尝试将数据从一个屏幕显示到 tabhost 中的一个选项卡,该选项卡由两个选项卡组成。
请在下面找到我的代码
主类.java
public class Demo_webserviceActivity extends Activity
{
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.editText1);
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(), Tab_1.class);
i.putExtra("gotonextpage", b.toString());
startActivity(i);
}
else
{
Toast.makeText(getApplicationContext(), "oops!.. empty",Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
Tab_1.java
public class Tab_1 extends Activity
{
TextView tv;
String result;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
result = extras.getString("gotonextpage");
}
tv = (TextView)findViewById(R.id.editText_tab1);
tv.setText(result);
}
}
谁能告诉我我在这里犯了什么错误?
谢谢你的时间!..