我正在尝试更改tabview的活动,并且我正在尝试访问名为“tabcontent”的framelayout。
我一直收到错误:
tabcontent cannot be resolved or is not a field.
即使它存在于我的.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" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
</TabWidget>
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="50dip"
android:layout_marginRight="50dip"
android:background="@drawable/attendance" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="50dip"
android:layout_marginLeft="50dip"
android:background="@drawable/sched" />
</FrameLayout>
</TabHost>
我在这里叫它:
//on Create
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
setTabs() ;
//Sets the visibility of the attendance and schedule buttons to invisible
Button attend = (Button)findViewById(R.id.button1);
Button sched = (Button)findViewById(R.id.button2);
attend.setVisibility(View.INVISIBLE);
sched.setVisibility(View.INVISIBLE);
contentviewlayout = (FrameLayout)findViewById(R.id.tabcontent); <--ERROR
contentviewparams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
我不知道为什么会发生这种情况......我会感激任何帮助!
答案 0 :(得分:1)
您应该使用android.R.id.tabcontent
,因为您要导入'your.app.package.R',而不是android.R:)