Skip to content

Commit 6c41388

Browse files
ymarianikim24
authored andcommitted
Bring back removed TabLayout method for compatibility
Resolves #903 We accidentally removed this since it wasn't in 1.0.0 and it was deprecated. It exists to keep compatibility with version 27.0 of the library. PiperOrigin-RevId: 289832106 (cherry picked from commit 17912e0)
1 parent 3e98044 commit 6c41388

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/java/com/google/android/material/tabs/TabLayout.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ public interface BaseOnTabSelectedListener<T extends Tab> {
432432
boolean tabIndicatorFullWidth;
433433
boolean unboundedRipple;
434434

435+
@Nullable private OnTabSelectedListener selectedListener;
436+
435437
private final ArrayList<OnTabSelectedListener> selectedListeners = new ArrayList<>();
436438
@Nullable private OnTabSelectedListener currentVpSelectedListener;
437439
private final HashMap<BaseOnTabSelectedListener<? extends Tab>, OnTabSelectedListener>
@@ -721,6 +723,25 @@ private void addTabFromItemView(@NonNull TabItem item) {
721723
addTab(tab);
722724
}
723725

726+
/**
727+
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
728+
* #removeOnTabSelectedListener(OnTabSelectedListener)}.
729+
*/
730+
@Deprecated
731+
public void setOnTabSelectedListener(@Nullable OnTabSelectedListener listener) {
732+
// The logic in this method emulates what we had before support for multiple
733+
// registered listeners.
734+
if (selectedListener != null) {
735+
removeOnTabSelectedListener(selectedListener);
736+
}
737+
// Update the deprecated field so that we can remove the passed listener the next
738+
// time we're called
739+
selectedListener = listener;
740+
if (listener != null) {
741+
addOnTabSelectedListener(listener);
742+
}
743+
}
744+
724745
/**
725746
* @deprecated Use {@link #addOnTabSelectedListener(OnTabSelectedListener)} and {@link
726747
* #removeOnTabSelectedListener(OnTabSelectedListener)}.

0 commit comments

Comments
 (0)