Add ActionBar tab callback method onTabReselected
onTabReselected is called if an already-selected tab is chosen again. For many apps this will be a no-op, but some may treat it as a signal to return to the top level of a given navigation category. Change-Id: Ic51fbe477b979562f2d848c4070b2016b217a90f
This commit is contained in:
@@ -19972,6 +19972,21 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<method name="onTabReselected"
|
||||
return="void"
|
||||
abstract="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="tab" type="android.app.ActionBar.Tab">
|
||||
</parameter>
|
||||
<parameter name="ft" type="android.app.FragmentTransaction">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onTabSelected"
|
||||
return="void"
|
||||
abstract="true"
|
||||
|
||||
@@ -470,5 +470,15 @@ public abstract class ActionBar {
|
||||
* will be executed in a single transaction.
|
||||
*/
|
||||
public void onTabUnselected(Tab tab, FragmentTransaction ft);
|
||||
|
||||
/**
|
||||
* Called when a tab that is already selected is chosen again by the user.
|
||||
* Some applications may use this action to return to the top level of a category.
|
||||
*
|
||||
* @param tab The tab that was reselected.
|
||||
* @param ft A {@link FragmentTransaction} for queuing fragment operations to execute
|
||||
* once this method returns.
|
||||
*/
|
||||
public void onTabReselected(Tab tab, FragmentTransaction ft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,18 +326,21 @@ public class ActionBarImpl extends ActionBar {
|
||||
|
||||
@Override
|
||||
public void selectTab(Tab tab) {
|
||||
if (mSelectedTab == tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
mActionView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
|
||||
final FragmentTransaction trans = mActivity.getFragmentManager().openTransaction();
|
||||
if (mSelectedTab != null) {
|
||||
mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
|
||||
}
|
||||
mSelectedTab = (TabImpl) tab;
|
||||
if (mSelectedTab != null) {
|
||||
mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
|
||||
|
||||
if (mSelectedTab == tab) {
|
||||
if (mSelectedTab != null) {
|
||||
mSelectedTab.getCallback().onTabReselected(mSelectedTab, trans);
|
||||
}
|
||||
} else {
|
||||
mActionView.setTabSelected(tab != null ? tab.getPosition() : Tab.INVALID_POSITION);
|
||||
if (mSelectedTab != null) {
|
||||
mSelectedTab.getCallback().onTabUnselected(mSelectedTab, trans);
|
||||
}
|
||||
mSelectedTab = (TabImpl) tab;
|
||||
if (mSelectedTab != null) {
|
||||
mSelectedTab.getCallback().onTabSelected(mSelectedTab, trans);
|
||||
}
|
||||
}
|
||||
|
||||
if (!trans.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user