电竞比分网-中国电竞赛事及体育赛事平台

分享

【轉】Android AlertDialog 使用方法

 techres 2010-12-06

Android AlertDialog 使用方法

看看這個程序,基本就會使用他了.

  1. package maximyudin.AlertDialogBuilderSample;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.widget.Button;
  5. import android.view.View;
  6. import android.app.AlertDialog;
  7. import android.content.DialogInterface;
  8. public class AlertDialogBuilderSample extends Activity {
  9. @Override
  10. public void onCreate(Bundle icicle) {
  11. super.onCreate(icicle);
  12. setContentView(R.layout.main);
  13. final Button btnQuit = (Button) findViewById(R.id.btnQuit);
  14. btnQuit.setOnClickListener(new Button.OnClickListener() {
  15. public void onClick(View v) {
  16. new AlertDialog.Builder(AlertDialogBuilderSample.this)
  17. .setTitle(“Question”)
  18. .setMessage(“Are you sure that you want to quit?”)
  19. .setIcon(R.drawable.question)
  20. .setPositiveButton(“Yes”, new DialogInterface.OnClickListener() {
  21. public void onClick(DialogInterface dialog, int whichButton) {
  22. setResult(RESULT_OK);
  23. finish();
  24. }
  25. })
  26. .setNegativeButton(“No”, new DialogInterface.OnClickListener() {
  27. public void onClick(DialogInterface dialog, int whichButton) {
  28. }
  29. })
  30. .show();
  31. }
  32. });
  33. final Button btnTravels = (Button) findViewById(R.id.btnTravels);
  34. btnTravels.setOnClickListener(new Button.OnClickListener() {
  35. public void onClick(View v) {
  36. new AlertDialog.Builder(AlertDialogBuilderSample.this)
  37. .setTitle(“I want to go to”)
  38. .setItems(R.array.items_indide_dialog,
  39. new DialogInterface.OnClickListener() {
  40. public void onClick(DialogInterface dialog, int whichcountry) {
  41. String[] travelcountries =
  42. getResources().getStringArray(R.array.items_indide_dialog);
  43. new AlertDialog.Builder(AlertDialogBuilderSample.this)
  44. .setMessage(“I’m going to “ + travelcountries[whichcountry])
  45. .setNeutralButton(“Cancel”,
  46. new DialogInterface.OnClickListener() {
  47. public void onClick(DialogInterface dialog, int whichButton)
  48. {
  49. }
  50. })
  51. .show();
  52. }
  53. })
  54. .show();
  55. }
  56. });
  57. }
  58. }

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多