0

I am making tabs in android. Currently this is how my tabs are working. When I click on any tab it will take me to appropriate tab's view which is fine. But lets say when I click on Profile tab then inside this profile view there is a button Add New. When I click on Add New button then it takes me to it's view but it also removes tabs from the view which I don't want. So how can I make tabs always available even when user clicks any link or button inside any view?

Here is my current code

tabs.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>

Tabs.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);
}
}

Profile.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

TabhostでActivityGroupを使用する必要があります

http://richipal.com/post/2624844577

ただし、ActivityGroups は廃止されているため、Tabhost で Fragments を使用する必要があります

于 2012-09-03T09:34:48.333 に答える