Я хочу создать приложение с вкладками, и я нашел это руководство http://developer.android.com/resources/tutorials/views/hello-tabwidget.html в Интернете, я решил следовать.
Я создал 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.Я спроектировал GuiRegistration в XML-файле, но мне также нужно добавить действия к кнопкам, например, поэтому я должен использовать класс 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);
}
}
Но, похоже, ничего не работает, может кто-нибудь сказать мне, как заставить это работать?