我创建了一个基于选项卡的应用程序,在其中一个选项卡中,还有内部选项卡,其中一些数据使用适配器以表格格式显示。在Android 2.1的所有设备上都完全没问题。但是在使用Android 2.2设备的所有设备中,它只显示第一个只有上方黑屏的标签。我给出了两个不同的截图供参考。
2.1设备的屏幕截图
2.2设备的屏幕截图
用于拼贴的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:id="@+id/myinfotrackerlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="bottom"
android:isScrollContainer="false"
android:scrollbarAlwaysDrawHorizontalTrack="false"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbars="none"
android:background="#FFFFFF"/>
</LinearLayout>
</TabHost>
Tabactivity代码
public class MyInfoTracker extends TabActivity {
private int tabid = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myinfotracker);
try{
final TabHost innerTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
Intent myint = this.getIntent();
tabid = myint.getIntExtra("tab_id", 0);
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","CD4");
// Initialize a TabSpec for each tab and add it to the TabHost
spec = innerTabHost.newTabSpec("CD4Count").setIndicator("CD4 Count").setContent(intent);
innerTabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","VL");
spec = innerTabHost.newTabSpec("ViralLoad").setIndicator("Viral Load").setContent(intent);
innerTabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
intent.putExtra("addType","Wt");
spec = innerTabHost.newTabSpec("Weight").setIndicator("Weight").setContent(intent);
innerTabHost.addTab(spec);
innerTabHost.setScrollbarFadingEnabled(false);
innerTabHost.setScrollContainer(false);
innerTabHost.setCurrentTab(tabid);
}catch(Exception e){}
}
}
可能导致此类问题的原因是什么?
答案 0 :(得分:0)
它根本不是与标签相关的概率。在onCreate()
中有一个代码 -
datePickerDialog = new DatePickerDialog(getParent(), ButtonTestDateListener,
mYear, mMonth, mDay);
我刚刚将mYear
,mMonth
和mDay
声明为整数,但没有初始化。它在2.1中运行良好,但在2.2中给出了概率。这就是为什么会出现这样的问题。