luchfilip

dialog

Aug 15th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. protected static TextView GroupName;
  2. protected static EditText rename_dialog_edit;
  3.  
  4. in onCreateView:
  5. GroupName = (TextView) view.findViewById(R.id.group_details_name);
  6. rename_dialog_edit = (EditText) view.findViewById(R.id.groupdetails_rename);
  7.  
  8. void showDialog() {
  9.         DialogFragment newFragment = MyAlertDialogFragment
  10.                 .newInstance(R.string.groupDetails_rename);
  11.         newFragment.show(getFragmentManager(), "dialog");
  12.     }
  13.  
  14. public static void doPositiveClick() {
  15.  
  16.         GroupName.setText(rename_dialog_edit.getText().toString());
  17.            
  18.         //Log.i("FragmentAlertDialog", "Positive click!");
  19.     }
  20.    
  21.     public static void doNegativeClick() {
  22.  
  23.         //Log.i("FragmentAlertDialog", "Negative click!");
  24.     }
  25.    
  26.     public static class MyAlertDialogFragment extends DialogFragment {
  27.  
  28.         public static MyAlertDialogFragment newInstance(int title) {
  29.             MyAlertDialogFragment frag = new MyAlertDialogFragment();
  30.             Bundle args = new Bundle();
  31.             args.putInt("title", title);
  32.             frag.setArguments(args);
  33.             return frag;
  34.         }
  35.  
  36.         @Override
  37.         public Dialog onCreateDialog(Bundle savedInstanceState) {
  38.             AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  39.             LayoutInflater inflater = getActivity().getLayoutInflater();
  40.             //int title = getArguments().getInt("title");
  41.  
  42.             return builder.setView(inflater.inflate(R.layout.group_details_rename_dialog, null))
  43.                     //.setIcon(R.drawable.logo)
  44.                     //.setTitle(R.string.groupDetails_rename)
  45.                     .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
  46.                @Override
  47.                public void onClick(DialogInterface dialog, int id) {
  48.                    doPositiveClick();
  49.                }
  50.                         })
  51.                             .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  52.                                    public void onClick(DialogInterface dialog, int id) {
  53.                                        doNegativeClick();
  54.                                    }
  55.                             })
  56.                             .create();
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment