0

我正在android中制作标签。目前这就是我的标签的工作方式。当我单击任何选项卡时,它会将我带到适当的选项卡视图,这很好。但是可以说,当我单击Profile选项卡时,在此profile视图中会有一个按钮Add New。当我单击Add New按钮时,它会将我带到它的视图,但它也会从视图中删除我不想要的选项卡。那么,即使用户单击任何视图内的任何链接或按钮,我如何才能使选项卡始终可用?

这是我当前的代码

选项卡.xml

<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">
<RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</RelativeLayout>
</TabHost>

标签.java

public class Tabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabs);

    Resources resources = getResources(); 
    TabHost tabHost = getTabHost();

    Intent startUseSaldo = new Intent().setClass(this, Usesaldo.class);
    TabSpec useSaldo = tabHost
      .newTabSpec("UseSaldo")
      .setIndicator("Use Saldo")
      .setContent(startUseSaldo);

    Intent startHistory = new Intent().setClass(this, History.class);
    TabSpec history = tabHost
      .newTabSpec("History")
      .setIndicator("History")
      .setContent(startHistory);

    Intent startProfile = new Intent().setClass(this, Profile.class);
    TabSpec profile = tabHost
      .newTabSpec("Profile")
      .setIndicator("Profile")
      .setContent(startProfile);

    // add all tabs 
    tabHost.addTab(useSaldo);
    tabHost.addTab(history);
    tabHost.addTab(profile);

    tabHost.setCurrentTab(1);
}
}

配置文件.java

public class Profile extends Activity {
Button bAddNew;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.profile);
    bAddNew = (Button)findViewById(R.id.bAddNew);

    bAddNew.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent AddFacility = new Intent(getApplicationContext(), AddFacility.class);
            startActivity(AddFacility);
        }
    });
}
}

AddFacility.java

public class AddFacility extends Activity {

@Override
public void setContentView(int layoutResID) {
    // TODO Auto-generated method stub
    super.setContentView(R.layout.add_facility);
}

}
4

2 回答 2

0

试试这个例子 - http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity

于 2012-09-03T09:26:50.133 回答
-1

您必须将 ActivityGroup 与 Tabhost 一起使用

http://richipal.com/post/2624844577

但是由于 ActivityGroups 已被废弃,您应该将 Fragments 与 Tabhost 一起使用

于 2012-09-03T09:34:48.333 回答