from:http://www.behestee.com/blog/?p=48
Android ListView Under a TabView
Here you will get how to add a list view in tab view. So go step by step:
1. Start a new project/Activity called TabWidget.
2. Open the layout file and make it like so:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<?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="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <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"> <ListView android:id="@+id/countries" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00FF00" android:layout_weight="1" android:drawSelectorOnTop="false"/> <TextView |
3. Now we’ll add our code. Open HelloTabWidget.java and make it a TabActivity.
By default, Eclipse creates a class that extends Activity. Change it to extend TabActivity:
1
|
public class TabWidget extends TabActivity {
|
4. Now fill in the the onCreate method like this:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost mTabHost = getTabHost(); |
5.Now write this under onCreate method like this:
1
2 3 4 5 6 |
static final String[] COUNTRIES = new String[] {
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium" }; |
6. That’s it. Run your application
It will be look like: