Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package mandatory.baa.android_mandatory_assignment_shopping_list.List;
  2.  
  3. import android.app.AlertDialog;
  4. import android.app.Dialog;
  5. import android.app.DialogFragment;
  6. import android.content.DialogInterface;
  7. import android.os.Bundle;
  8.  
  9. /**
  10. * Created by Mihai on 12/11/16.
  11. */
  12.  
  13. public class ResponseListenerFragment extends DialogFragment {
  14.  
  15. @Override
  16. public Dialog onCreateDialog(Bundle savedInstanceState) {
  17.  
  18. //Creates a new dialogBuilder;
  19. AlertDialog.Builder alert = new AlertDialog.Builder(
  20. getActivity());
  21. alert.setTitle("Confirmation");
  22. alert.setMessage("Are you sure?");
  23. alert.setPositiveButton("Yes", pListener);
  24. alert.setNegativeButton("No", nListener);
  25.  
  26. return alert.create();
  27. }
  28.  
  29. //Positive answer listener for when the user taps Yes
  30. DialogInterface.OnClickListener pListener = new DialogInterface.OnClickListener() {
  31.  
  32. @Override
  33. public void onClick(DialogInterface arg0, int arg1) {
  34. // Executed when user presses Yes
  35. positiveClick();
  36. }
  37. };
  38.  
  39. //Negative answer listener for when the taps No
  40. DialogInterface.OnClickListener nListener = new DialogInterface.OnClickListener() {
  41.  
  42. @Override
  43. public void onClick(DialogInterface arg0, int arg1) {
  44. // Executed when user presses No
  45. negativeClick();
  46. }
  47. };
  48.  
  49. //Empty, as they will be overridden
  50. protected void positiveClick()
  51. {
  52.  
  53. }
  54. protected void negativeClick()
  55. {
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement