Created
July 8, 2017 18:17
-
-
Save francisnnumbi/cc443862fa21f130fb9845f434a7fdf8 to your computer and use it in GitHub Desktop.
a demonstration of confirm dialog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.*; | |
import android.os.*; | |
import android.content.*; | |
public class MyDialog extends DialogFragment { | |
public static final int YES = 1, NO = 0, CANCEL = 2; | |
private String title, message; | |
private OnDismissListener listener; | |
private FragmentManager fragmentManager; | |
public MyDialog(FragmentManager fragmentManager, String title, String message) { | |
this.title = title; | |
this.fragmentManager = fragmentManager; | |
this.message = message; | |
listener = null; | |
} | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
// TODO: Implement this method | |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | |
builder.setTitle(title) | |
.setMessage(message) | |
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){ | |
@Override | |
public void onClick(DialogInterface p1, int p2) { | |
// TODO: Implement this method | |
listener.onDismiss(YES); | |
} | |
}) | |
.setNeutralButton("Cancel", new DialogInterface.OnClickListener(){ | |
@Override | |
public void onClick(DialogInterface p1, int p2) { | |
// TODO: Implement this method | |
listener.onDismiss(CANCEL); | |
} | |
}) | |
.setNegativeButton("No", new DialogInterface.OnClickListener(){ | |
@Override | |
public void onClick(DialogInterface p1, int p2) { | |
// TODO: Implement this method | |
listener.onDismiss(NO); | |
} | |
}); | |
return builder.create(); | |
} | |
public void show() { | |
show(fragmentManager, ""); | |
} | |
public void setOnDismissListener(MyDialog.OnDismissListener listener) { | |
this.listener = listener; | |
} | |
// listener interface | |
public interface OnDismissListener { | |
public void onDismiss(int confirm); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment