How to use Dialog Fragment? (showDialog deprecated) Android

后端 未结 4 1889
时光取名叫无心
时光取名叫无心 2020-11-28 13:08

I understand that there is this documentation

http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog

but as a new Android/Java le

4条回答
  •  借酒劲吻你
    2020-11-28 13:47

    Example of DialogFragment using Sherlock

    FragmentManager fm = getSherlockActivity().getSupportFragmentManager();
    DialogFragment dialog = new DialogFragment(){
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the Builder class for convenient dialog construction
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder
                .setTitle(getString(R.string.delete)+"?")
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    // do something
                    }
                })
                .setNegativeButton(getString(android.R.string.cancel),  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dismiss();
                    }
                });
            // Create the AlertDialog object and return it
            return builder.create();
        }
    };
    dialog.setCancelable(true);
    dialog.show(fm, "DELETE_DIALOG_FRAGMENT");
    

提交回复
热议问题