为什么我可以在另一个标签中看到一个标签内容

时间:2011-06-23 12:15:46

标签: java android android-layout

我想在我的程序中为Android 2.2实现三个选项卡,我已经成功实现了2个选项卡,但是当我添加第三个选项卡时,我可以看到选项卡3背面的选项卡2中的内容。第一个选项卡是从谷歌地图映射,第二个选项卡是地图搜索功能,第三个选项卡是首选项活动。

我认为解决方案在此代码中的某处。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    // Adding tabbing feature
    mTabHost = getTabHost();
    TabSpec tabSpec = mTabHost.newTabSpec("Map1");
    tabSpec.setIndicator("Map1",
            getResources().getDrawable(R.drawable.globe));
    Context ctx = this.getApplicationContext();
    Intent i = new Intent(ctx, MapTabView.class);
    tabSpec.setContent(i);
    mTabHost.addTab(tabSpec);

mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
    .setIndicator("Filtered         Search",getResources().getDrawable(R.drawable.glass)).setContent(R.id.textview2));


TabSpec tabPref = mTabHost.newTabSpec("Preferences");
tabPref.setIndicator("Preferences",getResources().getDrawable(R.drawable.preferences));
Context ctx2 = this.getApplicationContext();
Intent l = new Intent (ctx2, Preferences.class);
tabPref.setContent(l);
mTabHost.addTab(tabPref);

这是我正在使用的示例首选项xml

<?xml version="1.0" encoding="utf-8"?>

    <PreferenceCategory
            android:title="First Category">
            <CheckBoxPreference
                    android:title="Checkbox Preference"
                    android:defaultValue="false"
                    android:summary="This preference can be true or false"
                    android:key="checkboxPref" />
            <ListPreference
                    android:title="List Preference"
                    android:summary="This preference allows to select an item in a array"
                    android:key="listPref"
                    android:defaultValue="digiGreen"
                    android:entries="@array/listArray"
                    android:entryValues="@array/listValues" />
    </PreferenceCategory>
    <PreferenceCategory
            android:title="Second Category">
    <EditTextPreference
            android:name="EditText Preference"
            android:summary="This allows you to enter a string"
            android:defaultValue="Nothing"
            android:title="Edit This Text"
            android:key="editTextPref" />
    <RingtonePreference
            android:name="Ringtone Preference"
            android:summary="Select a ringtone"
            android:title="Ringtones"
            android:key="ringtonePref" />
    <PreferenceScreen
            android:key="SecondPrefScreen"
            android:title="Second PreferenceScreen"
            android:summary="This is a second PreferenceScreen">
            <EditTextPreference
                    android:name="An other EditText Preference"
                    android:summary="This is a preference in the second PreferenceScreen"
                    android:title="Edit text"
                    android:key="SecondEditTextPref" />
    </PreferenceScreen>
    <Preference
            android:title="Custom Preference"
            android:summary="This works almost like a button"
            android:key="customPref" />
    </PreferenceCategory>

0 个答案:

没有答案