I want to create an Application with tabs, and I have found this guide http://developer.android.com/resources/tutorials/views/hello-tabwidget.html on the Internet, I have choosen to follow.
I have created an XML-file for the Layout, that looks like this:
<?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>
I also created a class to create the Tabs due to the guide, which is shown below.
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");
}
}
Now I need to generate the content of the tabs, where one of the tabs is GuiRegistration.
I have designed the GuiRegistration in a XML-file, but I also need to add actions to buttons e.g., so I have to use the GuiRegistration-class. But how can I create the tab, because I have tried usingsetContentView(R.layout.registration)
Design the tab directy in the class
And
public class GuiRegistration extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View aTabLayout = findViewById(R.id.aTableLayout);
Vi开发者_StackOverflowewGroup 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);
}
}
But nothing seems to work, can somebody tell me how to make it work?
from the code, your Guiregistration class is not calling setContentView(R.layout.registration)
May be thats why the view is not drawn in the tab.
精彩评论