Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.example.first;
  2.  
  3. import android.content.DialogInterface;
  4. import android.support.v7.app.AlertDialog;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.Toast;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13. private String[] items = {"망고","포도","딸기"};
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19.  
  20. Button List = (Button) findViewById(R.id.List);
  21. List.setOnClickListener(new View.OnClickListener() {
  22. @Override
  23. public void onClick(View v) {
  24. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  25. builder.setTitle("리스트");
  26. builder.setItems(items, new DialogInterface.OnClickListener() {
  27. @Override
  28. public void onClick(DialogInterface dialog, int i) {
  29. Toast.makeText(getApplicationContext(), items[i], Toast.LENGTH_SHORT).show();
  30. }
  31. });
  32. AlertDialog alertDialgo = builder.create();
  33. alertDialgo.show();
  34. }
  35. });
  36.  
  37. Button Exit = (Button) findViewById(R.id.Exit);
  38. Exit.setOnClickListener(new View.OnClickListener() {
  39. @Override
  40. public void onClick(View v) {
  41. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  42. builder.setMessage("정말로 종료하시겠습니까?");
  43. builder.setTitle("종료 알림창")
  44. .setCancelable(false)
  45. .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  46. @Override
  47. public void onClick(DialogInterface dialog, int i) {
  48. finish();
  49. }
  50. })
  51. .setNegativeButton("No", new DialogInterface.OnClickListener() {
  52. @Override
  53. public void onClick(DialogInterface dialog, int i) {
  54. dialog.cancel();
  55. }
  56. });
  57. AlertDialog alert = builder.create();
  58. alert.setTitle("종료 알림창");
  59. alert.show();
  60. }
  61. });
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement