Hi I'm a real novice at android and really getting desperate at this apparently simple attempt with TabActivity. The application crashes with the "stopped unexpectedly" error. I've tried to run code from online tutorials but same error every time. So here is the embarrassingly simple code.
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class MainLanding extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlandingtab);
TabHost mainLandingTab = getTabHost();
TabHost.TabSpec spec;
Intent intent = new Intent().setClass(this, AccountActivity.class);
spec = mainLandingTab.newTabSpec("account");
spec.setContent(intent);
spec.setIndicator("Account");
mainLandingTab.addTab(spec);
mainLandingTab.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
intent = new Intent().setClass(this, ProfileActivity.class);
spec.setContent(intent);
spec.setIndicator("Profile");
mainLandingTab.addTab(spec);
mainLandingTab.getTabWidget().getChildAt(1).getLayoutParams().height = 40;
intent = new Intent().setClass(this, SocialActivity.class);
spec.setContent(intent);
spec.setIndicator("Social");
mainLandingTab.addTab(spec);
mainLandingTab.getTabWidget().getChildAt(2).getLayoutParams().height = 40;
}
}
Here is the mainlandingtab.xml file.
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/tabHost"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@android:id/tabs" />
<FrameLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@android:id/tabcontent"/>
</LinearLayout>
</TabHost>
And the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobile.banking" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:name=".StartupActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainLanding" />
<activity android:name=".AccountActivity" />
<activity android:name=".ProfileActivity" />
<activity android:name=".SocialActivity" />
<activity android:name=".SignInActivity"></activity>
</application>
</manifest>
There are other activities also in the application which to run fine but when MainLanding class is called, it crashes.
The logcat error says: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
I have no idea what's wrong with this code. Please help!!