Dont want to show Tab Layout on perticular tab click - android

I have used a TabHost in my application with three tabs suppose A, B and C...
In general when we click on any tab it will open new activity "with TAB LAYOUT", but i want to do something different When I do click on tab c an Intent should be shown and I don't want tab layout for that Intent
How can I do it?
Thanking you all!!!

You can do it by setting tab change listener:
getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
if (tabId.equalsIgnoreCase(cTabId))
startActivity(intentForCActivity);
}
});
But you should understand that this is bad idea - user will wonder what happens. It's not the best practice to wonder user with creating nonobvious interface decisions.

Related

How to clear the Child activities on clicking the particular tab

I want to know how to clear child activities and how to invoke the parent activity of a particular tab on its second click (tab functionality like on iPhone?). I want to invoke the click listener for each tab. Assume as if the application gets deeper while using, it's hard to use the back button often to reach the parent activity. So i need to invoke the parent activity by clicking the tab.
On first tab it is working fine, here is the code
getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (getTabHost().getCurrentTabTag().equals("gebrauchte")) {
Intent intent = new Intent(getApplicationContext(),TabHome.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else{
tabs.setCurrentTab(0);
}
}
});
I tried to use the same code for the second tab with getChildAt(1), should i give TabHome class for all intent, if I try to give their respective class of 2nd, 3rd and 4th tab, the tabHost gets hidden.
You don't need to set onClickListener on Tabs. I would advice to use Android Tabs with Fragments

Tab issue in android with back button

I am using tab host(tabs) in application, it have four tabs on home screen, I have set new layouts on every tabs, I want to that once user clicking tabs like: tab1>tab2>tab3>tab4 and press back on tab4 he/she should go back to tab3 and on tab3 pressing back go to tab2 and so on. I didn't get any idea, how to implement? Could any one help me on this, any help will be appreciated. Thanking you all..!!
Create the below method in your class which extends TabActivity,
public void switchTabBar(int tab) {
tabHost.setCurrentTab(tab);
}
And now in your activity's back press method, do this,
public void onBackPressed() {
TabBar parentTab = (TabBar) this.getParent();
parentTab.switchTabBar(1);//Instead of 1 provide the tab position which you want to navigate to.
}
you can override onBackPressed() and inside it do what you want.
I dont know why you want to add back button.In tabs there's no need to add back button.See the below link
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
You need to create some sort of a activities-backstack (if you use nested ActivityGroup), override onBackPressed() method in your TabActivity and manage this backstack in onBackPressed() method.
You have 2 options:- with Tab or without Tab.
If it is not necessary that you have to use tab in your code then instead of tab you can use buttons and you can easily get your goal. But if you want to use tab then you have to Override onBackPressed() in every 4 Activity.
I hope you got any idea according to my answer. I hope it helps you.

How to make the back button switch between tabs

I have an application first showing a login screen which on a succesful login changes to a tab view with 3 tabs. Each tab is containing a different activity. When I switch between the tabs I would like the back button to return to the previous tab instead of the login screen.
How should the be done? I'm considering implementing onBackPressed on the tab view and remembering the tab-stack manually but I don't feel that is the right approach.
Let say you have tabs created in class called Main.java. Create there method like this:
public void switchTab(int tab) {
tabHost.setCurrentTab(tab);
}
which will change current tab. Next in activity where you want to change navigation insert the following code:
#Override
public void onBackPressed() {
Main m = (Main)getParent();
m.switchTab(0);
}
This should work.

Android tabs event

I stuck with one problem. actually my screen consists of two tabs. under each tab i have 4-4 activity. i m displaying each activity with the help of activity group in single tab.
Suppose i m in 1st tab which is active. Under this tab i m on 2nd activity(e.g first activity is list activity and second activity gives the result from the first activity)
I want when i click on 1st tab again it should show me the first activity again without using back button.?
I had that problem sometime ago... and that happens because people like to emulate the bottom bar of the iPhone. Android apps don't work that way and using Activity Group is always a signal of a poor UI design.
Anyway, this is what I did:
tabHost.setCurrentTabByTag(TAB_ID_MORE);
tabHost.getCurrentTabView().setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if( MoreGroupActivity.self != null ) {
MoreGroupActivity.self.reset();
}
tabHost.setCurrentTabByTag(TAB_ID_MORE);
}
});
tabHost.setCurrentTabByTag(TAB_ID_HOME);
The above code is not generic, but will give you an idea of the workaround I found. Let me explain:
tabHost.setCurrentTabByTag(TAB_ID_MORE); I use this to select a current tab (in my case, the main tab was another tab, so I had to to this and then change back with tabHost.setCurrentTabByTag(TAB_ID_HOME);). I mean, in my case, the only tab with that behavior was the "More" tab.
tabHost.getCurrentTabView().setOnClickListener this allows you to put a listener to the tab. As you may have already noticed, using OnChangeTabListener is not an option in this kind of situation.
MoreGroupActivity.self Inside my group activity, I had a static field referencing the group activity it self. This kind of hacks are common while using this crappy approach.
tabHost.setCurrentTabByTag(TAB_ID_MORE); this reset the tab so that it can change back to your first activity.
When you are adding a new TabHost.TabSpec to the TabHost
use
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
to the respective Intent

Problem with back button on emulator when multiple activities are there in single tab

I have created two tabs, say TAB1 and TAB2. For TAB1, i have loaded one Activity, say ActivityOne, into TAB1 as
Intent intent = new Intent(this,ActivityOne.class);
TabHost.TabSpec spec = getTabHost().newTabSpec("ActivityOne")
.setIndicator("Activity One",getResources().getDrawable(R.drawable.artists)).setContent(intent);
getTabHost().addTab(spec);
This ActivityOne has extended the ActivityGroup and i added one button in this activity. By clicking on this button it will call another activity, say ActivityOne_One, as
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(ActivityOne.this,ActivityOne_One.class);
replaceContentView("ActivityOne_One",intent);
}
public void replaceContentView(String id, Intent intent){
View view = this.getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
When we click on that button ActivityOne_One will be launched under same TAB1. In this application i have two problems:
1) If i want to go back to ActivityOne under same TAB1 by using traditional BACK button on emulator it is not working..
2)ActivityOne_One is launching with no animation(like sliding from right to left) effect.
If anyone know about any one of these, give your advice..
Thanks,
venu
I have found the solution for my question. The following blog gave me a route for this
http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
see this link which may help you out with this. http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
i have implemented what is advised in the link i provided. it works OK, but it is quirky and does not always redirect you BACK like you would expect. i have found that you must implement your own custom tabs to really get this desired effect.

Categories

Resources