Reputation: 143
I am trying to make tabs layout. I am using tutorial code (below) but it doesn't work. LogCat gives this error:
04-19 19:02:16.297: ERROR/AndroidRuntime(455): java.lang.RuntimeException: Unable to start activity ComponentInfo{jusbrz.bakalauras/jusbrz.bakalauras.FilesTabsActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
I added new activitys to manifest.
XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
Using this code in main activity:
package jusbrz.bakalauras;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class FilesTabsActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.files_tabs_layout);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, AllFilesTabActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Visi").setIndicator("Visi").setContent(intent);
tabHost.addTab(spec);
}
}
So where might be the problem?
EDITED
import android.app.TabActivity;
import android.os.Bundle;
public class AllFilesTabActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_files_tab_layout);
}
}
Upvotes: 0
Views: 237
Reputation: 132992
you are missing tabhost id in layout.update your layout as:
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost">
Update your class FilesTabsActivity :
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("Visi");
firstTabSpec.setIndicator("Visi").setContent(new Intent(this,AllFilesTabActivity.class));
/** Add tabSpec to the TabHost to display. */
tabHost.addTab(firstTabSpec);
AND IF YOU ARE IF YOU ARE ADDING TAB DYNAMICALLY:
setContentView(R.layout.files_tabs_layout);
Upvotes: 1
Reputation: 83301
If you are going to use TabActivity
, you need to use @android:id/tabhost
as the android ID value of your TabHost
.
Browsing a few other questions on StackOverflow, it also seems that doing a "Projects --> Clean" and restarting Eclipse might help too.
Upvotes: 0