问题描述
我有型TabActivity的新意图,我希望你能在正确的方向指向我用TabHost的问题。有趣地它工作正常,当我尝试查看它的原意:的setContentView(R.layout.main)
我得到一个强制关闭,并在logcat中,我得到以下错误,即使我的Tabhost ID =@android:ID / tabhost:
我已经宣布在manifest.xml文件中的第二个目的:XML:
<活动机器人:NextActivity名称=机器人:标签=@字符串/ APP_NAME>
在第一个活动(MainActivity),我开始了第二个意图(NextActivity),与临时演员,如下:
意图nextActivity =新的意图(MainActivity.this,NextActivity.class);
捆绑b_next在=新包();
b_next.putString(s_string,myString的);
nextActivity.putExtras(b_next在);
在我NextActivity.java文件,我得到了群众演员,并尝试以显示TabHost查看:
公共类NextActivity扩展TabActivity {
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
字符串myString的;
捆绑b_initial;
b_initial = getIntent()getExtras()。
MyString的= b_initial.getString(s_string);
的setContentView(R.layout.main);
}
}
我得到同样的错误使用上的Android开发者网站(Hellow视图)TabHost例如:
main.xml中:
< XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的TextView
机器人:ID =@ + ID / textview1
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:文本=这是一个标签/>
<的TextView
机器人:ID =@ + ID / textview2
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:文本=这是另一个选项卡/>
<的TextView
机器人:ID =@ + ID / textview3
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:文本=这是第三个选项卡/>
< /的FrameLayout>
< / LinearLayout中>
< / TabHost>
在此先感谢乡亲...
澄清:这是我从LogCat中真正得到:
我有previously构建tabhosts与 Android的一个id:ID =@ + ID / tabhost
。为你工作的呢?
您还可以考虑以编程方式构建您的选项卡视图:
TabHost T = getTabHost();
则tabspec标签= t.newTabSpec(标签)
.setIndicator(标签,图标)
.setContent(意向);
t.addTab(标签);
I am having an issue with using TabHost in a new Intent of type TabActivity which I hope you can point me in the right direction. Funnily it works fine when I try to view it in the original Intent : setContentView(R.layout.main)
I get a "forced closed" and within logcat, I get the following error even though my Tabhost id = "@android:id/tabhost":
I have declared the second intent in the Manifest.xml file:XML:
<activity android:name=".NextActivity" android:label="@string/app_name" >
Within the first activity (MainActivity), I start the second intent (NextActivity), with extras, as follows:
Intent nextActivity = new Intent(MainActivity.this,NextActivity.class);
Bundle b_next=new Bundle();
b_next.putString("s_string", myString);
nextActivity.putExtras(b_next);
In my NextActivity.java file, I get the extras and try to display the TabHost View:
public class NextActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myString;
Bundle b_initial;
b_initial = getIntent().getExtras();
myString = b_initial.getString("s_string");
setContentView(R.layout.main);
}
}
I get the same error with using the TabHost example on the Android Developer site (Hellow View):
Main.xml:
<?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>
Thanks in advance folks...
CLARIFICATION:This is what I really get from LogCat:
I have previously constructed tabhosts with an id of android:id="@+id/tabhost"
. Does this work for you?
You could also consider constructing your tab view programmatically:
TabHost t = getTabHost();
TabSpec tab = t.newTabSpec(label)
.setIndicator(label, icon)
.setContent(intent);
t.addTab(tab);
这篇关于问题在新的意向书显示TabHost布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!