我想创建标签而不扩展TabActivity.(原因是TabActivity无法处理自定义标题栏).我有
public class startTab extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
Resources res = getResources();
LocalActivityManager mlam = new LocalActivityManager(this, false);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup(mlam);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, Show1.class);
spec = tabHost.newTabSpec("Items").setIndicator("Items", res.getDrawable(R.drawable.items32_ldpi)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Show2.class);
spec = tabHost.newTabSpec("Users").setIndicator("Users",res.getDrawable(R.drawable.user32_ldpi)).setContent(intent);
tabHost.addTab(spec);
}
Run Code Online (Sandbox Code Playgroud)
}
我得到的错误是
07-02 07:11:12.715: ERROR/AndroidRuntime(411):
Caused by: java.lang.IllegalStateException: Activities can't be added until the containing group has been created.
Run Code Online (Sandbox Code Playgroud)
视图的xml是
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud) 我一直在尝试实现本教程中描述的选项卡UI:https://developer.android.com/resources/tutorials/views/hello-tabwidget.html
我按照说明的过程中的所有步骤,但我不断收到有关每个选项卡的内容运行时异常我相信这事做,没有一个地方在教程中,我添加了额外的活动(歌曲,艺术家和专辑)的事实进入android清单文件.
我对么?本教程(像许多其他人一样)是错误还是不完整?
我需要示例代码在android中创建TabHost.谁能帮我.
我一直在关注Google提供的Tab示例.我正在尝试使用提供的XML布局来设置选项卡布局.
我使用这个XML布局@ http://developer.android.com/guide/tutorials/views/hello-tabwidget.html
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)
当我在Eclipse布局设计器中切换Layout选项卡时,我在Eclipse中得到一个NullPointerException:null错误.
当我尝试拖放TabHost,然后将TabWidget拖放到空布局文件中时,也会发生这种情况.
我究竟做错了什么 ?这看起来很简单.