I have a activity Main which extends from SherlockFragmentActivity. In this activity Main, I have 3 tabs(Tab1, Tab2 and Tab3), they extend from SherlockFragment.
Now, How to launch Main's the Tab3 when I click at a button from other activity.
You can pass some extra params in the intent you are using to start the activity Main. You can do something like intent.putExtra(key,value), and after that in the Main activity inside onCreate() you can do getIntent.getExtras() and you will be able to start whatever fragment you want
In first activity
intent.putExtra("tabs", 2);
In activity with tab:
int tab_index = getIntent().getExtras().getInt("tab",0);
tabs.setCurrentTab(tab_index);
Related
How to can I go from one activity to another activity view pager fragment and also that fragment contain view pager which contain two fragment and i want to go 2 nd fragment. I want to go 2nd fragment
I am trying replace fragment but it give No view found Exception .
and also try To Intent through i send value true value to the destination Activity and try to open that 2nd fragment . but I am not able to open that .
How to achieve that
Use an intent to specify the desired position of your viewpager before changing the activity
Intent mIntent = new Intent(A.this, B.class)
mIntent.putExtra("pager_position",1) // 0 in case you want the first fragment
startActivity(mIntent)
In the B Activity, the one with viewpager, make sure your viewpager and FragmentPagerAdapter are initialized before getting the data from the intent.
After that you simply put this:
Bundle extras = getIntent().getExtras();
int pageIndex = extras.getInt("pager_position")
mViewPager.setCurrentItem(pageIndex)
In second Activity set mViewPager.setCurrentItem(1)
My app is structured like this
MainActivity --> getToolbar()
fragment a
fragment b : starts GetDetailsActivity
GetDetailsActivity() : needs to call getToolbar()
Fragments a & b are started from Main.
b can start GetDetailsActivity.
How should I pass are reference to MainActivity to GetDetailsActivity in order for GetDetails to call getToolbar
What's the proper way?
You should not pass an activity as a reference to another activity. Each activity should have its own Toolbar as ActionBar, defined in its layout file. Just like you have a toolbar in MainActivity's XML layout, you should have another one for DetailsActivity's XML layout.
I have created 3 tabs using tabhost in the MaintabActivity;
TaboneActivity
TabtwoActivity
TabthreeActivity
there is a button in the TabtwoActivity, when i click on it , anohter activity called OutofServiceActivity.java is displayed.
my problem is when iam trying to call TabtwoActivity from OutofServiceActivity.java it will rediect to TabtwoActivity without showing the tab bar..?
what s the problem??
Give a call to TabHost.setCurrentTab(--tab id here--) in onCreate method when you set your activities.
I created a tabbed application in which I have three tabs.
In the first activity I am opening a class named Home.class and inside the Home.class I want to start another activity that should open in that tab itself is it possible.
Please help.
ActivityGroup is deprecated, try to use Fragment and FragmentManager
To start multiple Activity in one tab, you need to extend your tab with ActivityGroup. and when are you starting new Activity you need to use startChildActivity
Use Android ActivityGroup within TabHost to show different Activity
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.