Skip to content

Instantly share code, notes, and snippets.

@ntlv
Last active January 1, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntlv/8151679 to your computer and use it in GitHub Desktop.
Save ntlv/8151679 to your computer and use it in GitHub Desktop.
show a fragment
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