我在android中制作标签。目前这是我的标签工作的方式。当我点击任何标签时,它将带我到适当的标签视图,这很好。但是,当我点击Profile
标签然后在profile
视图中有一个按钮Add New
时,我们就说了。当我点击Add New
按钮时,它会将我带到它的视图,但是它还会从视图中删除我不想要的标签。那么即使用户如何使标签始终可用点击任意视图中的任何链接或按钮?
这是我目前的代码
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);
}
}
答案 0 :(得分:0)
试试这个例子 - http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity
答案 1 :(得分:-1)
您必须将ActivityGroup与Tabhost一起使用
http://richipal.com/post/2624844577
但是当ActivityGroups被禁止时,你应该使用带有Tabhost的碎片