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
Related
I have an activity which has four tab. first tab has list view and some list item . after clicking on list item i want to open an activity on the same tab (first tab).
I couldn't find any solution of that.
help me !! Thanks
There is a way to open a new activity, which is with an Intent, so you can do the following:
Intent intent=new Intent(Activity.this or this,Activity2.class);
//here you can add the flags you might need
startActivity(intent);
The activity Activity.this or this is the one that launches the new Activity, so the code must be inside the Activity that is showing the tab you are using.For example, if you need to change the title you can add the following:
#Override
public void onResume()
{
super.onResume();
this.getParent().setTitle("Your title");
}
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.
ShareMarketActivity.java this handles the tabs, Tab1, Tab2, Tab3.java files..... which on load it load the 1st tab
in Tab3 (portfolio) when u click on the company it moves to another window, what i want to do is,when u click back button on the new window... it should again load the tabs and it moves to the Tab3.
back.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("android.intent.action.ShareMarketActivity"));
}
});
So this will load the tabs again and show the tab1 as the starting tab. Not the Tab3. what i want is... ** load the ShateMarketActivity and straight away moves to tab3 ** ( in the 1st load i want Tab1 to be the 1st load not tab3)
You can use the setCurrentTab method of the tab host.
mTabHost.setCurrentTab(2);
What you need to do is listed briefly below. I am not putting any code though but it should be straightforward.
When you are navigating to a new window do not navigate through the child activities that reside in the TAB Host. Call getParent() and then start new Activity from the TabActivity which is the Parent.
Make the Tab launchmode in manifest as SingleTask.
You can not capture the result of the Activity in onActivityResult in TabHost and then call the child Activity to propogate the result by using getCurrentActivity()
The reason for the behavior you see is that Tabs are actually an ActivityGroup with multiple activities embedded in them for each TAB. Once you call a new Activity from any of the child Activity and then come back the Activity stack loses the Activity Group and lists the calling activity as parent and hence you just see TAB3 activity as the only activity.
Let me know if this does not help.
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
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.