我想创建一个带有选项卡的应用程序,并且我在Internet上找到了本指南http://developer.android.com/resources/tutorials/views/hello-tabwidget.html,我选择了遵循。Android Tabs with TableLayout
我已经创建了一个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="50dip">
<LinearLayout 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" />
<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp">
<TableLayout android:id="@+id/aTableLayout" android:layout_width="fill_parent" android:layout_height="fill_parent">
</TableLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
我还创建了一个类来创建标签由于指南,如下所示。
public class GuiTabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabslayout);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, GuiRegistration.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Reg").setIndicator("Registration").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTabByTag("Reg");
}
}
现在我需要生成的标签,其中一个选项卡是GuiRegistration的内容。
我设计了一个XML文件中的GuiRegistration,但我也需要添加动作到按钮,例如,所以我必须使用GuiRegistration类。
但我怎么能创建的标签,因为我一直在使用
setContentView(R.layout.registration)
设计中的类
而且
public class GuiRegistration extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View aTabLayout = findViewById(R.id.aTableLayout);
ViewGroup vGroup = (ViewGroup) aTabLayout.getParent();
int index = vGroup.indexOfChild(aTabLayout);
vGroup.removeViewAt(index);
View newTabLayout = getLayoutInflater().inflate(R.layout.registration, vGroup, false);
vGroup.addView(newTabLayout, index);
}
}
但似乎没有任何工作的标签directy试过了,可有人告诉我如何使它工作?
你的问题不清楚,请更具体地 – 2011-05-30 16:31:32
我想你也需要tabhost。 – Tsunaze 2011-05-30 17:39:25
我现在编辑了这个问题,所以我希望能够更加明确 – The87Boy 2011-05-30 17:45:39