Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setTabSFromPagerAdapter is deprecated

right now i m using latest version of appcompat and design support library.

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

now i m facing some deprecation

 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);
}

anyone know what i have to use instead.. help me.. thank you

like image 533
Sagar Chavada Avatar asked Mar 11 '16 16:03

Sagar Chavada


1 Answers

This is from 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 just like Nikola Despotoski said in comment, calling setupWithViewPager is enough.

like image 129
Adi Nugroho Avatar answered Sep 28 '22 06:09

Adi Nugroho