Hi, I am trying to write a simple application that creates a new tab. The view structure is:
FrameLayout -- TabHost -------TabWidget -------FrameLayout The code is shown below: public class P4Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public void onStart() { super.onStart(); //We can try to add tabs and related views programmatically here createAdditionalViews(); } private void createAdditionalViews() { /* TextView tv = new TextView(this); tv.setText("Test view"); */ TabHost thRoot = new TabHost(this); TabWidget tabs = new TabWidget(this); tabs.setId(android.R.id.tabs); thRoot.addView(tabs); FrameLayout tabcontent = new FrameLayout(this); tabcontent.setId(android.R.id.tabcontent); thRoot.addView(tabcontent); thRoot.setup(); TabHost.TabSpec tabSetup = thRoot.newTabSpec("Setup"); tabSetup.setIndicator("Setup"); TextView tv1 = new TextView(this); tv1.setText("This is the Setup tag."); tabSetup.setContent(tv1.getId()); thRoot.addTab(tabSetup); thRoot.setCurrentTabByTag("Setup"); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams (ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); this.addContentView(thRoot, lp); } } When I run it, it crashes at the line: tabSetup.setContent(tv1.getId()); The debug call stack is as below: ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2266 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord) line: 2284 ActivityThread.access$1800(ActivityThread, ActivityThread $ActivityRecord) line: 112 ActivityThread$H.handleMessage(Message) line: 1692 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3948 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 782 ZygoteInit.main(String[]) line: 540 NativeStart.main(String[]) line: not available [native method] What am I missing/doing wrong? Thanks, AS --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---