我需要构建一个复选框,当该对话框被选中时,它将不再显示。请帮助我不知道该怎么做的人
MyDialogFragment.class
public class MyDialogFragment extends DialogFragment {
private CheckBox checkBox;
public static MyDialogFragment newInstance(int title, int message) {
MyDialogFragment frag = new MyDialogFragment();
Bundle args = new Bundle();
args.putInt("title", title);
args.putInt("message", message);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
int message = getArguments().getInt("message");
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
return builder
.setTitle(getString(getArguments().getInt("title")))
.setMessage(getString(getArguments().getInt("message")))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
dismiss();
}
})
.create();
}
}
在片段上调用对话框
DialogFragment newFragment = MyDialogFragment.newInstance(R.string.title_dialog1, R.string.message_dialog2);
newFragment.show(getFragmentManager(), "dialog");