안드로이드 다이얼로그(AlertDialog)에 관련된 예제입니다.

package com.example.teste22;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setTitle("호박이Title");
  builder.setMessage("호박이 Body MSG");
  builder.setIcon(android.R.drawable.ic_dialog_alert);
  builder.setPositiveButton("OK", new OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(getApplicationContext(), "Clicked", 3).show();
   }
  });
  builder.setNegativeButton("Cancel", new OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(getApplicationContext(), "Clicked Cancel", 3)
      .show();
   }
  });
  builder.setNeutralButton("Netural", new OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(getApplicationContext(), "Neutral Clicked", 3)
      .show();
    AlertDialog ad = builder.create();
    ad.cancel();
   }
  });
  builder.setOnCancelListener(new OnCancelListener() {
   @Override
   public void onCancel(DialogInterface dialog) {
    Toast.makeText(getApplicationContext(), "토스트 메세지", 3).show();
   }
  });
  builder.show();
 }
}




실행 결과


Posted by 준콩ol 준콩ol

댓글을 달아 주세요