Android : launching diff activities under TabWidget
- by rahul
hiii
I am trying to launch activities under each tab.
I hav tried with following code
public class Tab_Proj1 extends TabActivity {
TabHost mTabHost ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Context context = getApplicationContext();
//mTabHost = (TabHost) this.findViewById(R.id.);
mTabHost = getTabHost();
mTabHost.setup();
mTabHost.addTab(mTabHost.newTabSpec("tab_test4")
.setIndicator("Contacts")
.setContent(new Intent().setClass(context, Tab1Activity.class)));
Tab1Activity is extending ListActivity.
I m getting exception as::::::
01-25 11:57:07.352: ERROR/AndroidRuntime(952): Uncaught handler: thread main exiting due to uncaught exception
01-25 11:57:07.382: ERROR/AndroidRuntime(952): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.app.Tab_Proj1/com.android.app.Tab_Proj1.Tab_Proj1}: java.lang.RuntimeException: Could not create tab content because could not find view with id 2131034148
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.os.Looper.loop(Looper.java:123)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.main(ActivityThread.java:3948)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at dalvik.system.NativeStart.main(Native Method)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): Caused by: java.lang.RuntimeException: Could not create tab content because could not find view with id 2131034148
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:539)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:530)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.widget.TabHost$TabSpec.setContent(TabHost.java:417)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at com.android.app.Tab_Proj1.Tab_Proj1.onCreate(Tab_Proj1.java:52)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-25 11:57:07.382: ERROR/AndroidRuntime(952): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
======================================================================
Am I going in correct way?
If not please help me with some ideas.....
thanks