2012-06-14 21 views
1

Emulator's image顯示結果在tabhost上機器人蝕

上述圖像只是添加兩個值,並顯示在下面的TextView結果。 但我需要在下一個屏幕上的tabhost的第一個選項卡(ie.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(); 
     } 
    } 
    }); 
    } 
} 

:此源實際上是消費來自機器人一個web服務和表示由SOAP方法

非常感謝的結果。

+1

'Fragment'或'ActivityGroup'可以是你的幫助。 –

+0

你有沒有嘗試過任何代碼? – Praveenkumar

+0

Hi-SpK,是的,我試過一些,但它沒有在tabhost上顯示結果,只顯示在單個頁面上 –

回答

0

您可以使用共享偏好來存儲值,那麼你就可以訪問它在項目的任何活動:

關注該link