The tabs at the bottom stop working once I click on the second tab.
Could anyone please help?

Here is some code.


// Main Activity

public class MainTabActivity extends TabActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                /** TabHost will have Tabs */
                TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

                /** TabSpec used to create a new tab.
                 * By using TabSpec only we can able to setContent to the tab.
                 * By using TabSpec setIndicator() we can set name to tab. */

                /** tid1 is firstTabSpec Id. Its used to access outside. */
                TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
                TabSpec secondTabSpec = tabHost.newTabSpec("tid1");

                /** TabSpec setIndicator() is used to set name for the tab. */
                /** TabSpec setContent() is used to set content for a particular
tab. */
                firstTabSpec.setIndicator("View Map").setContent(new
Intent(this,FirstTab.class));
                secondTabSpec.setIndicator("Route Information").setContent(new
Intent(this,SecondTab.class));

                /** Add tabSpec to the TabHost to display. */
                tabHost.addTab(firstTabSpec);
                tabHost.addTab(secondTabSpec);

        }
}


// First Tab Activity

public class FirstTab extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                /* First Tab Content */
                TextView textView = new TextView(this);
                textView.setText("First Tab");
                setContentView(textView);

        }
}


// Second Tab Activity with ListView

public class SecondTab extends ListActivity{
        /** Called when the activity is first created. */

        static final String[] stops = new String[] {
                "Odegard", "Memorial Union"};

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);


                setListAdapter(new ArrayAdapter<String>(this,
R.layout.second_tab_layout, stops));

                ListView lv = getListView();
                lv.setTextFilterEnabled(true);


                lv.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View 
view,
                                        int position, long id) {
                                // When clicked, show a toast with the TextView 
text
                                Toast.makeText(getApplicationContext(), 
((TextView)
view).getText(),
                                                Toast.LENGTH_SHORT).show();
                        }
                });


        }


// Second tab activity xml layout file

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>


//First activity xml layout file


<?xml version="1.0" encoding="utf-8"?>

<TabHost android:layout_width="fill_parent"
        android:layout_height="fill_parent" xmlns:android="http://
schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost">
        <RelativeLayout android:id="@+id/LinearLayout01"
                android:orientation="vertical" 
android:layout_height="fill_parent"
                android:layout_width="fill_parent">
                <TabWidget android:id="@android:id/tabs"
                        android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"></TabWidget>
                <FrameLayout android:id="@android:id/tabcontent"
                        android:layout_height="fill_parent"
android:layout_width="fill_parent"></FrameLayout>
        </RelativeLayout>

</TabHost>


// xml manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.und.shuttleRoute6"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:label="@string/app_name"
android:name=".MainTabActivity" android:theme="@android:style/
Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
                <activity android:name=".FirstTab" />
                <activity android:name=".SecondTab" />
    </application>
</manifest>



Thanks for any help!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to