2012-06-22 48 views
0

在tabhost的标签数据我有即四项活动,无法显示在Android

  • Demo_tabActivity.java [主要活动]

  • Tabhost.java

的下面两个活动是上述tabhost的选项卡.java

  • Tab_1.java

  • Tab_2.java

第一个活动(Demo_tabActivity.java)包含一个EditText & button.The第二(Tabhost.java)活性包含Tabhost widget.The第三&第四活动包含textviews分别。

第一个活动将通过从用户获取输入并返回tabhost(第二个活动)的第一个选项卡(第三个活动)上的某些数据来使用Web服务。

web服务的好消费工作状态良好,完全返回值,

,但问题是,它显示了单独的页面,而不是显示在tabhost的结果。

Demo_tabActivity.java

public class Demo_tabActivity 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.button1); 

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

     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 itnt = new Intent(v.getContext(), Tab_1.class); 
       itnt.putExtra("gotonextpage", b.toString()); 
       startActivity(itnt); 
      } 
      else 
      { 
      Toast.makeText(getApplicationContext(), "NoResponse",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.textView_main2); 
tv.setText(result); 
}} 

Tabhost.java

public class Tabhost extends TabActivity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main1); 


    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    intent = new Intent().setClass(this, Tabhost.class); 
    spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, Tab_2.class); 
    spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
    } 
} 
+0

您shuld发表您的tabhost代码了。 – Barak

+0

@Barak请再次访问我的问题,我已经包括tabhost.java –

回答

0

你的问题,是因为你不包括tab_1中你tabhost(你是自参考TabHost ...不知道怎么说不是导致飞机坠毁... )。

我相信这行:需要

intent = new Intent().setClass(this, Tabhost.class); 

改变这个(或添加另一个则tabspec吧):

intent = new Intent().setClass(this, Tab_1.class);