Activity:
package com.link.view;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import com.link.R;
public class MainActivity extends TabActivity implements OnClickListener{
TabHost mth;
private Button btn1,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mth = this.getTabHost();
TabSpec Tab1 = mth.newTabSpec("1").setIndicator("1");
Tab1.setContent(new Intent(this, Activity1.class));
mth.addTab(Tab1);
TabSpec Tab2 = mth.newTabSpec("2").setIndicator("2");
Tab2.setContent(new Intent(this, Activity2.class));
mth.addTab(Tab2);
btn1=(Button)findViewById(R.id.check);
btn2=(Button)findViewById(R.id.newkind);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.check:
mth.setCurrentTabByTag("1");
break;
case R.id.newkind:
mth.setCurrentTabByTag("2");
break;
}
}
}
.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="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/check"
android:text="acitvity1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/newkind"
android:text="activity2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</TabHost>