Guest User

Untitled

a guest
Mar 19th, 2019
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2. public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  3. super.onActivityCreated(savedInstanceState);
  4.  
  5. if (getView() != null) {
  6. getView().setFocusableInTouchMode(true);
  7. getView().requestFocus();
  8. getView().setOnKeyListener(new View.OnKeyListener() {
  9. @Override
  10. public boolean onKey(View v, int keyCode, KeyEvent event) {
  11. if (event.getAction() == KeyEvent.ACTION_DOWN) {
  12. if (keyCode == KeyEvent.KEYCODE_BACK) {
  13. // Here Write code for transfer fragment.
  14. ChangeCurrentFragment(new FragmentC);
  15. return true;
  16. }
  17. }
  18. return false;
  19. }
  20. });
  21. }
  22. }
  23.  
  24. private void ChangeCurrentFragment(Fragment fragment) {
  25. //hideKeyBoard();
  26. FragmentManager fManager = getSupportFragmentManager();
  27. FragmentTransaction fTransaction = fManager.beginTransaction();
  28. fTransaction.setCustomAnimations(R.anim.fragment_enter_anim, R.anim.fragment_exit_anim);
  29. fTransaction.replace(R.id.layoutFHostFragment, fragment, fragment.getClass().getName());
  30. fTransaction.commitAllowingStateLoss();
  31. }
  32.  
  33. @Override
  34. public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  35. super.onActivityCreated(savedInstanceState);
  36.  
  37. if (getView() != null) {
  38. getView().setFocusableInTouchMode(true);
  39. getView().requestFocus();
  40. getView().setOnKeyListener(new View.OnKeyListener() {
  41. @Override
  42. public boolean onKey(View v, int keyCode, KeyEvent event) {
  43. if (event.getAction() == KeyEvent.ACTION_DOWN) {
  44. if (keyCode == KeyEvent.KEYCODE_BACK) {
  45. // Here Write code for transfer fragment.
  46. ChangeCurrentFragment(new FragmentB);
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. });
  53. }
  54. }
RAW Paste Data