Guest User

Untitled

a guest
Aug 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. Android ; Confirm app exit
  2. final String phoneNumber;
  3. phoneNumber = "5555555555";
  4.  
  5. ImageButton callButton = (ImageButton)findViewById(R.id.btnCall);
  6.  
  7. callButton.setOnClickListener(new OnClickListener(){
  8. public void onClick(View v) {
  9. try {
  10. Intent callIntent = new Intent(Intent.ACTION_DIAL);
  11. callIntent.setData(Uri.parse("tel:"+phoneNumber));
  12. startActivity(callIntent);
  13. } catch (ActivityNotFoundException activityException) {
  14. Log.e("Calling a Phone Number", "Call failed", activityException);
  15. }
  16. }
  17. });
  18.  
  19. callButton.setOnClickListener(new OnClickListener(){
  20. public void onClick(View v) {
  21. OnClickListener listener = new OnClickListener(){
  22. @Override
  23. public void onClick(DialogInterface dialog, int which) {
  24. if(which == Dialog.BUTTON_POSITIVE)
  25. {
  26. try {
  27. Intent callIntent = new Intent(Intent.ACTION_DIAL);
  28. callIntent.setData(Uri.parse("tel:"+phoneNumber));
  29. startActivity(callIntent);
  30. } catch (ActivityNotFoundException activityException) {
  31. Log.e("Calling a Phone Number", "Call failed", activityException);
  32. }
  33. }
  34. }
  35. };
  36.  
  37. new AlertDialog.Builder(v.getContext())
  38. .setMessage("Are you sure you want to leave the application?")
  39. .setPositiveButton("Yes", listener)
  40. .setNegativeButton("No", listener)
  41. .show();
  42. }
  43. }
  44.  
  45. AlertDialog.Builder alert = new AlertDialog.Builder(this);
  46.  
  47. alert.setTitle("Title");
  48. alert.setMessage("Message");
  49.  
  50. // Set an EditText view to get user input
  51. final EditText input = new EditText(this);
  52. alert.setView(input);
  53.  
  54. alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  55. public void onClick(DialogInterface dialog, int whichButton) {
  56. String value = input.getText();
  57. // Do something with value!
  58. }
  59. });
  60.  
  61. alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  62. public void onClick(DialogInterface dialog, int whichButton) {
  63. // Canceled.
  64. }
  65. });
  66.  
  67. alert.show();
Add Comment
Please, Sign In to add comment