Last active
January 1, 2016 13:29
-
-
Save ntlv/8151679 to your computer and use it in GitHub Desktop.
show a fragment
This file contains hidden or 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
private void showFragmentRoutine(Class<?> fragment, String tag) { | |
try { | |
FragmentManager fm = getFragmentManager(); | |
if (fm.findFragmentByTag(tag) != null) { | |
fm.popBackStack(tag, 0); | |
} else { | |
fm.beginTransaction() | |
.replace(R.id.container, (Fragment) Class.forName(fragment.getName()).newInstance(), tag) | |
.addToBackStack(tag) | |
.commit(); | |
} | |
} catch (ClassNotFoundException e) { | |
tabSpawnExceptionHandler(e); | |
} catch (IllegalAccessException e) { | |
tabSpawnExceptionHandler(e); | |
} catch (InstantiationException e) { | |
tabSpawnExceptionHandler(e); | |
} | |
} | |
private void tabSpawnExceptionHandler(Exception e) { | |
e.printStackTrace(); | |
Toast.makeText(this, "Något gick fel när en flik skulle visas", Toast.LENGTH_SHORT).show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment