0

I wanna add three layout in a TabActivity, but it was force closed when I ran it.

Here is the code:

import android.app.TabActivity; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost;

public class Test1 extends TabActivity {

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     Resources res = getResources(); 
     TabHost tabHost = getTabHost();      

    tabHost.addTab(tabHost.newTabSpec("egcquery").setIndicator("EGCQuery").setContent(R.layout.main1)); 
    tabHost.addTab(tabHost.newTabSpec("PatientInfo").setIndicator("PatientInfo").setContent(R.layout.main2)); 
    tabHost.addTab(tabHost.newTabSpec("Comp_Interp").setIndicator("Comp_Interp").setContent(R.layout.main3));
}

}

Kooper
  • 715
  • 1
  • 10
  • 13

1 Answers1

0

See my answer to this question: Why do I get an error while trying to set the content of a tabspec in android?

Community
  • 1
  • 1
Tim Kryger
  • 11,166
  • 4
  • 52
  • 41
  • Thanks for your answer.But I change this it is still force closed :( tabHost.addTab(tabHost.newTabSpec("egcquery").setIndicator("EGCQuery").setContent(R.id.L1)); tabHost.addTab(tabHost.newTabSpec("PatientInfo").setIndicator("PatientInfo").setContent(R.id.L2)); tabHost.addTab(tabHost.newTabSpec("Comp_Interp").setIndicator("Comp_Interp").setContent(R.id.L3)); – Kooper Jun 12 '10 at 19:09
  • Did you add the corresponding android:id tag to your xml layout files? – Tim Kryger Jun 12 '10 at 19:16
  • Yes, I've already added. Like this: – Kooper Jun 12 '10 at 19:19
  • What exception are you getting now? – Tim Kryger Jun 12 '10 at 19:28
  • I just see "The application Test1(process irdc.test1)has stopped unexpectedly. Please try again". Could you tell me how to find the reason?? – Kooper Jun 12 '10 at 19:42
  • Try single stepping through your code in the debugger and see when it fails. – Tim Kryger Jun 12 '10 at 19:51
  • In the Debugger window , the "Method.invokeNative" and "NativaStart.main" lines show that can't be used. – Kooper Jun 12 '10 at 19:59
  • At first I put three Activity in a TabActivity and it can works. But I wanna set TextView in Tab2 by clicking a button in Tab1. An member tell me use layout is much easier, no Activity. I've tried but it didn't success util now :( . – Kooper Jun 12 '10 at 20:30