embedding layout inside each tab? - (each tab has its own activity)
- by Abhi
I have started with the HelloTabwidget example and it works fine. Now what I am trying to do is have a layout inside each tab. here is what the code looks like
myApp extends TabActivity {
TabHost tabHost;
onCreate() {
setContentView (R.layout.main);
tabHost = getTabHost();
TabHost.tabspec spec = tabHost.newTabSpec(..).setIndicator(...).
setContent(new Intent().setClass(...));
tabHost.addTab(spec);
:
}
}
myTab1Actvity extends Activity {
ListView myLV;
EditText myET;
onCreate() {
setcontentView (TAB1_LAYOUT);
myLV = findViewById(..);
:
myLV.setAdapter(aa);
myET.setOnKeyListener(....)
registerforContextMenu(myLV)
}
}
when I run here is the stack trace
ERROR/AndroidRuntime(691): java.lang.NullPointerException
ERROR/AndroidRuntime(691): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
ERROR/AndroidRuntime(691): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
ERROR/AndroidRuntime(691): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
ERROR/AndroidRuntime(691): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
ERROR/AndroidRuntime(691): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(691): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(691): at android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(691): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(691): at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Does the code's flow look OK? basically each Tab has its own activity and each tab has its own layout.
It appears that something is wrong in the TabHost - but I am unable to pinpoint it. Any suggestions/Qs you hav e will be very helpful.