AlertDialog を使ってみた

AlertDialog は
java.lang.Object
  ↳ android.app.Dialog
    ↳ android.app.AlertDialog
を使います

というわけで、AlertDialog をいじってみた

サンプルプログラム
  1. import android.app.Activity;  
  2. import android.app.AlertDialog;  
  3. import android.content.DialogInterface;  
  4. import android.os.Bundle;  
  5.   
  6. public class AlertDialogTest extends Activity {  
  7.   AlertDialog.Builder alertDialogBuilder;  
  8.   @Override  
  9.   public void onCreate(Bundle savedInstanceState) {  
  10.     super.onCreate(savedInstanceState);  
  11.     setContentView(R.layout.main);  
  12.   
  13.     alertDialogBuilder = new AlertDialog.Builder(this);  
  14.   
  15.     // Title を設定  
  16.     alertDialogBuilder.setTitle("Title");  
  17.   
  18.     // Message を設定  
  19.     alertDialogBuilder.setMessage("Message");  
  20.   
  21.     // Icon を設定  
  22.     alertDialogBuilder.setIcon(R.drawable.icon);  
  23.   
  24.     // Positive Button を設定  
  25.     alertDialogBuilder.setPositiveButton(  
  26.       "Positive",  
  27.       new DialogInterface.OnClickListener() {  
  28.         // Positive Button がクリックされた時の動作  
  29.         public void onClick(DialogInterface dialog, int which) {  
  30.   
  31.         }  
  32.       }  
  33.     );  
  34.   
  35.     // Neutral Button を設定  
  36.     alertDialogBuilder.setNeutralButton(  
  37.       "Neutral",   
  38.       new DialogInterface.OnClickListener() {  
  39.         // Neutral Button がクリックされた時の動作  
  40.         public void onClick(DialogInterface dialog, int which) {  
  41.   
  42.         }  
  43.       }  
  44.     );  
  45.   
  46.     // Negative Button を設定  
  47.     alertDialogBuilder.setNegativeButton(  
  48.       "Negative",   
  49.       new DialogInterface.OnClickListener() {  
  50.         // Negative Button がクリックされた時の動作  
  51.         public void onClick(DialogInterface dialog, int which) {  
  52.   
  53.         }  
  54.       }  
  55.     );  
  56.   
  57.     // AlertDialog を表示  
  58.     alertDialogBuilder.create().show();  
  59.   }  
  60. }  

プログラムを実行すると...



こんな感じ!

0 件のコメント:

コメントを投稿