我是 android 编程新手,需要高级用户来检查我的工作。出于某种原因,当我运行此应用程序时,我得到一个空白屏幕,而不是我想要的两个选项卡。非常感谢!
MainActivity.java
package com.example.storeitemfinder3;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.layout.tab1);
spec1.setIndicator("Tab 1");
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(R.layout.tab2);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
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" />
<include layout="@layout/tab1" />
<include layout="@layout/tab2" />
</TabHost>
tab1.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/Avocados"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Avocados" />
<CheckBox
android:id="@+id/Cashew_Nuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cashew_Nuts"
/>
////android:checked="true"
</LinearLayout>
tab2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.81"
android:src="@drawable/tjs" />
</LinearLayout>