Irlance_Dox

DialogFragm

Aug 28th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package com.example.hoa.dialog;
  2.  
  3. import android.app.DialogFragment;
  4. import android.app.FragmentManager;
  5. import android.content.Context;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.ImageButton;
  11. import android.widget.TextView;
  12.  
  13.  
  14. public class DialogFragm extends DialogFragment {
  15.  
  16.     private static final String TAG = "DialogFragm";
  17.  
  18.     public interface OnInputListner{
  19.         void sendInput(String Input);
  20.     }
  21.     public OnInputListner mOnInputListner;
  22.  
  23.     ImageButton event1;
  24.     ImageButton event2;
  25.     ImageButton event3;
  26.     ImageButton event4;
  27.     String type ;
  28.  
  29.     @Override
  30.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  31.                              Bundle savedInstanceState) {
  32.         // Inflate the layout for this
  33.         View v = inflater.inflate(R.layout.fragment_dialog, container, false);
  34.  
  35.         event1 = (ImageButton)v.findViewById(R.id.imageButton);
  36.         event1.setOnClickListener(new View.OnClickListener(){
  37.             @Override
  38.             public void onClick(View v) {
  39.  
  40.                 type = "道路施工";
  41.  
  42.                 FragmentManager newFragment = getFragmentManager();
  43.                 Dialog2 myDialog = new Dialog2();
  44.                 //Dialog2 myDialog = (Dialog2) getActivity().getFragmentManager().findFragmentByTag("Dialog2");
  45.  
  46.                 mOnInputListner.sendInput(type);
  47.                 myDialog.show(newFragment,"Dialog2");
  48.                 getDialog().dismiss();
  49.             }
  50.         });
  51.  
  52.         event2 = (ImageButton)v.findViewById(R.id.imageButton2);
  53.         event3 = (ImageButton)v.findViewById(R.id.imageButton3);
  54.         event4 = (ImageButton)v.findViewById(R.id.imageButton4);
  55.  
  56.         return v;
  57.     }
  58.  
  59.  
  60.     @Override
  61.     public void onAttach(Context context) {
  62.         super.onAttach(context);
  63.         try{
  64.             mOnInputListner = (OnInputListner)getTargetFragment() ;
  65.         }catch(ClassCastException e){
  66.         }
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment