Reputation: 2707
I am using ViewPager
with ActionBar
Tabs and I easily can swipe between tabs(fragment
s), and I also can open another tab onClick
of that tab.
But, I want to on button click from one tab to open another tab(fragment).
Take a look on the picture below.
Upvotes: 1
Views: 2523
Reputation: 20102
After creating your Tab, store the tab in a variable so that it is accessable in your Buttons onClick
method. Then call the ActionBar.Tab.select() method inside your onClick
method of your button.
Use something like this: (I could not check everything, but it should give you the idea)
ActionBar actionBar = getActivity().getActionBar();
final Tab tab = actionBar.newTab();
Button button = new Button(getActivity());
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
tab.select();
}
}
Upvotes: 1
Reputation: 2707
Here is how I solved this problem:
private ActionBar actionBar;
Then I put this in onCreate()
actionBar = getActivity().getActionBar();
And then I created button on click listener like this:
btnLocationReviews.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
actionBar.setSelectedNavigationItem(3);
}
Upvotes: 1