Facebook
From Tiny Wolf, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 260
  1. package jakubstokowski.exercise3;
  2.  
  3. import android.content.Context;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.v4.app.Fragment;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10.  
  11.  
  12. /**
  13.  * A simple {@link Fragment} subclass.
  14.  * Activities that contain this fragment must implement the
  15.  * {@link Fragment11.OnFragmentInteractionListener} interface
  16.  * to handle interaction events.
  17.  */
  18. public class Fragment11 extends Fragment {
  19.  
  20.     private OnFragmentInteractionListener mListener;
  21.  
  22.     public Fragment11() {
  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.fragment11, container, false);
  32.     }
  33.  
  34.     // TODO: Rename method, update argument and hook method into UI event
  35.     public void onButtonPressed(Uri uri) {
  36.         if (mListener != null) {
  37.             mListener.onFragmentInteraction(uri);
  38.         }
  39.     }
  40.  
  41.     @Override
  42.     public void onAttach(Context context) {
  43.         super.onAttach(context);
  44.         if (context instanceof OnFragmentInteractionListener) {
  45.             mListener = (OnFragmentInteractionListener) context;
  46.         } else {
  47.             throw new RuntimeException(context.toString()
  48.                     + " must implement OnFragmentInteractionListener");
  49.         }
  50.     }
  51.  
  52.     @Override
  53.     public void onDetach() {
  54.         super.onDetach();
  55.         mListener = null;
  56.     }
  57.  
  58.     /**
  59.      * This interface must be implemented by activities that contain this
  60.      * fragment to allow an interaction in this fragment to be communicated
  61.      * to the activity and potentially other fragments contained in that
  62.      * activity.
  63.      * <p>
  64.      * See the Android Training lesson <a href=
  65.      * "http://developer.android.com/training/basics/fragments/communicating.html"
  66.      * >Communicating with Other Fragments</a> for more information.
  67.      */
  68.     public interface OnFragmentInteractionListener {
  69.         // TODO: Update argument type and name
  70.         void onFragmentInteraction(Uri uri);
  71.     }
  72. }
  73.