Reputation: 201
Like in topic - I want to create activity above tabHost that I already have.
I have button inside one of the tab and after click event I want to create activity that will overlay tabHost.
Another question is how to make it on application launch (It has to be hidden sometimes).
Upvotes: 0
Views: 1261
Reputation: 6666
Try this
final (Button) yourButton = (Button)getViewById(R.id.your_button);
yourButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent(v.getContext(), YourActivity.class);
startActivityForResult(intent, 0);
}
});
YourActivity is the activity you wish start.
Upvotes: 2
Reputation: 1427
you try this code
public class Test_tedActivity extends TabActivity {
/** Called when the activity is first created. */
TabHost tabhost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
// TabHost tabhost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this,Add.class);
spec = tabhost.newTabSpec("Add")
.setIndicator("add",res.getDrawable(R.drawable.plus)).setContent(intent);
tabhost.addTab(spec);
intent = new Intent(this,Show.class);
spec = tabhost.newTabSpec("Show")
.setIndicator("Show",res.getDrawable(R.drawable.information)).setContent(intent);
tabhost.addTab(spec);
intent = new Intent(this,Edit.class);
spec = tabhost.newTabSpec("Edit")
.setIndicator("Edit",res.getDrawable(R.drawable.edit)).setContent(intent);
tabhost.addTab(spec);
tabhost.setCurrentTab(2);
}
}
xml this used
<?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:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
mainfest this one
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ketan.test" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Test_tedActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Add" android:label="Add"></activity>
<activity android:name=".Edit" android:label="Edit"></activity>
<activity android:name=".Show" android:label="Show"></activity>
</application>
</manifest>
Upvotes: 0