SetTabSFromPagerAdapter deprecated

right now i'm using the latest version of the application and design support library.

compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1' 

now i am facing some outdated

  private void setupTabLayout() { mTabLayout = (TabLayout)findViewById(R.id.tab_layout); mAdapter = new MyPagerAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mTabLayout.setTabsFromPagerAdapter(mAdapter); <!-- deprecated --> mTabLayout.setupWithViewPager(mPager); } 

does anyone know what i should use instead .. help me .. thanks

+5
source share
1 answer

This is from the TabLayout documentation on setTabsFromPagerAdapter :

 /** * @deprecated Use {@link #setupWithViewPager(ViewPager)} to link a TabLayout with a ViewPager * together. When that method is used, the TabLayout will be automatically updated * when the {@link PagerAdapter} is changed. */ @Deprecated public void setTabsFromPagerAdapter(@Nullable final PagerAdapter adapter) { setPagerAdapter(adapter, false); } 

So, as Nicola Despotoski said in a comment, just call setupWithViewPager .

+10
source

Source: https://habr.com/ru/post/1244899/


All Articles