Java Code Examples for com.google.android.material.tabs.TabLayout#OnTabSelectedListener
The following examples show how to use
com.google.android.material.tabs.TabLayout#OnTabSelectedListener .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SensorCardPresenter.java From science-journal with Apache License 2.0 | 5 votes |
public void setOnSensorSelectedListener(final OnSensorClickListener listener) { onSensorClickListener = listener; onTabSelectedListener = new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { if (cardViewHolder != null) { String newSensorId = (String) tab.getTag(); trySelectingNewSensor(newSensorId, sensorId); } } @Override public void onTabUnselected(TabLayout.Tab tab) {} @Override public void onTabReselected(TabLayout.Tab tab) { if (cardViewHolder != null) { String newSensorId = (String) tab.getTag(); if (TextUtils.equals(sensorId, newSensorId) && sensorPresenter != null) { sensorPresenter.resetView(); // Also need to pin the graph to now again. interactionListener.requestResetPinnedState(); } else { trySelectingNewSensor(sensorId, newSensorId); } } } }; if (cardViewHolder != null && isActive) { cardViewHolder.sensorTabLayout.clearOnTabSelectedListeners(); cardViewHolder.sensorTabLayout.addOnTabSelectedListener(onTabSelectedListener); } }
Example 2
Source File: TabLayoutHelper.java From android-tablayouthelper with Apache License 2.0 | 4 votes |
/** * Constructor. * * @param tabLayout TabLayout instance * @param viewPager ViewPager instance */ public TabLayoutHelper(@NonNull TabLayout tabLayout, @NonNull ViewPager viewPager) { PagerAdapter adapter = viewPager.getAdapter(); if (adapter == null) { throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set"); } mTabLayout = tabLayout; mViewPager = viewPager; mInternalDataSetObserver = new DataSetObserver() { @Override public void onChanged() { handleOnDataSetChanged(); } }; mInternalOnTabSelectedListener = new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { handleOnTabSelected(tab); } @Override public void onTabUnselected(TabLayout.Tab tab) { handleOnTabUnselected(tab); } @Override public void onTabReselected(TabLayout.Tab tab) { handleOnTabReselected(tab); } }; mInternalTabLayoutOnPageChangeListener = new FixedTabLayoutOnPageChangeListener(mTabLayout); mInternalOnAdapterChangeListener = new ViewPager.OnAdapterChangeListener() { @Override public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter oldAdapter, @Nullable PagerAdapter newAdapter) { handleOnAdapterChanged(viewPager, oldAdapter, newAdapter); } }; setupWithViewPager(mTabLayout, mViewPager); }