Created
September 16, 2019 17:01
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdaptadorViewPager extends FragmentPagerAdapter { | |
private final List<Fragment> listaDeFragmentos = new ArrayList<>(); | |
private final List<String> listaDeTitulosDeFragmentos = new ArrayList<>(); | |
AdaptadorViewPager(FragmentManager manager) { | |
super(manager); | |
} | |
@Override | |
public Fragment getItem(int position) { | |
return listaDeFragmentos.get(position); | |
} | |
@Override | |
public int getCount() { | |
return listaDeFragmentos.size(); | |
} | |
void agregarFragmento(Fragment fragment, String title) { | |
listaDeFragmentos.add(fragment); | |
listaDeTitulosDeFragmentos.add(title); | |
} | |
// Si es el título de la última pestaña, regresamos null, lo | |
// cual regresará el icono únicamente | |
@Override | |
public CharSequence getPageTitle(int position) { | |
if (position >= getCount() - 1) return null; | |
return listaDeTitulosDeFragmentos.get(position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment