I have a navigation view for which I use this switch to change my fragment depending on the item selected :
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (viewId) {
case R.id.nav_random:
fragment = new Random();
title = "RANDOM";
break;
case R.id.nav_podium:
fragment = new Podium();
title = "PODIUM";
break;
case R.id.nav_sport:
fragment = new Sport();
title = "SPORT";
break;
case R.id.nav_videogames:
fragment = new Games();
title = "GAMES";
break;
case R.id.nav_socialnetwork:
fragment = new SocialNetwork();
title = "SOCIAL NETWORKS";
break;
case R.id.nav_heart:
fragment = new Heart();
title = "FAVORITES";
break;
}
I want to check if the fragment selected is "Podium" or whichever else, how can I do that? I have tried something like if fragment == new Podium() or if fragment == Podium but I can't figure out how to check which fragment is selected and then displayed.
Aucun commentaire:
Enregistrer un commentaire