当前位置 : 主页 > 编程语言 > java >

DialogFragmentUtil工具类

来源:互联网 收集:自由互联 发布时间:2022-06-23
import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.AppCompatActivity; public class DialogF
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;

public class DialogFragmentUtil {

public static void showSingleDialog(AppCompatActivity activity, String title, String msg, String positive,
DialogInterface.OnClickListener listener) {
createSingleDialog(title, msg, positive, listener)
.show(activity.getSupportFragmentManager(), activity.getClass().getSimpleName() + "Dialog");
}

public static void showDoubleDialog(AppCompatActivity activity, String title, String msg, String positive,
String negative, DialogInterface.OnClickListener listener) {
createDoubleDialog(title, msg, positive, negative, listener)
.show(activity.getSupportFragmentManager(), activity.getClass().getSimpleName() + "Dialog");
}


public static DialogFragment createSingleDialog(String title, String msg, String positive,
DialogInterface.OnClickListener listener) {
return AlertDialogFragment.newSingleInstance(title, msg, positive, listener);
}

public static DialogFragment createDoubleDialog(String title, String msg, String positive,
String negative, DialogInterface.OnClickListener listener) {
return AlertDialogFragment.newDoubleInstance(title, msg, positive, negative, listener);
}

public static class AlertDialogFragment extends DialogFragment {

private static DialogInterface.OnClickListener mListener;

public static AlertDialogFragment newSingleInstance(String title, String msg, String positive,
DialogInterface.OnClickListener listener) {
return newDoubleInstance(title, msg, positive, null, listener);
}

public static AlertDialogFragment newDoubleInstance(String title, String msg, String positive,
String negative, DialogInterface.OnClickListener listener) {
AlertDialogFragment frag = new AlertDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
args.putString("msg", msg);
args.putString("negative", negative);
args.putString("positive", positive);
mListener = listener;
frag.setArguments(args);
return frag;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String title = getArguments().getString("title");
String msg = getArguments().getString("msg");
String positive = getArguments().getString("positive");
String negative = getArguments().getString("negative");

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(title)
.setMessage(msg)
.setPositiveButton(positive, mListener);

if (negative != null) {
builder.setNegativeButton(negative, mListener);
}
return builder.create();
}
}
}

DialogFragmentUtil工具类

往哪里看到的了,侵删


上一篇:安卓 屏幕旋转
下一篇:没有了
网友评论