안드로이드 다이얼로그

2013. 5. 30. 08:49Mobile/Android



반응형

 

 [안드로이드,Android]다이어로그,AlerDialog (버튼3개)-확인,중립,취소

 

 

 

 

 

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("까리 타이틀");
  builder.setMessage("까리 바디 메세지");
  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();
 }
}

반응형