Advertisement
dhohoney

CategoryFragmenT

Mar 30th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. package com.dicoding.myflexiblefragment;
  2.  
  3. import android.os.Bundle;
  4.  
  5. import androidx.annotation.NonNull;
  6. import androidx.annotation.Nullable;
  7. import androidx.fragment.app.Fragment;
  8. import androidx.fragment.app.FragmentManager;
  9. import androidx.fragment.app.FragmentTransaction;
  10.  
  11. import android.view.LayoutInflater;
  12. import android.view.View;
  13. import android.view.ViewGroup;
  14. import android.widget.Button;
  15.  
  16.  
  17. /**
  18. * A simple {@link Fragment} subclass.
  19. */
  20. public class CategoryFragment extends Fragment implements View.OnClickListener {
  21.  
  22. public CategoryFragment() {
  23. // Required empty public constructor
  24. }
  25.  
  26.  
  27. @Override
  28. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  29. Bundle savedInstanceState) {
  30. // Inflate the layout for this fragment
  31. return inflater.inflate(R.layout.fragment_category, container, false);
  32. }
  33.  
  34. @Override
  35. public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  36. super.onViewCreated(view, savedInstanceState);
  37. Button btnDetailCategory = view.findViewById(R.id.btn_detail_category);
  38. btnDetailCategory.setOnClickListener(this);
  39. }
  40.  
  41. @Override
  42. public void onClick(View v) {
  43. if (v.getId() == R.id.btn_detail_category){
  44. DetailCategoryFragment mDetailCategoryFragment = new DetailCategoryFragment();
  45.  
  46. Bundle mBundle = new Bundle();
  47. mBundle.putString(DetailCategoryFragment.EXTRA_NAME, "Lifestyle");
  48. String description = "Kategori ini akan berisi produk-produk lifestyle";
  49.  
  50. mDetailCategoryFragment.setArguments(mBundle);
  51. mDetailCategoryFragment.setDescription(description);
  52.  
  53. FragmentManager mFragmentManager = getFragmentManager();
  54. if (mFragmentManager != null){
  55. mFragmentManager
  56. .beginTransaction()
  57. .replace(R.id.frame_container, mDetailCategoryFragment, DetailCategoryFragment.class.getSimpleName())
  58. .addToBackStack(null)
  59. .commit();
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement