package soo.ui.notify; import android.app.Activity; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import android.app.AlertDialog.Builder; public class AlertDialog extends Activity implements OnClickListener { /** Called when the activity is first created. */ Button b1,b2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); b1 = (Button)findViewById(R.id.button01); b2 = (Button)findViewById(R.id.button02); b1.setOnClickListener(this); b2.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v==b1){ Builder ad = new Builder(this); //AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("대화창 제목"); ad.setMessage("대화창 내용"); ad.setNeutralButton("닫기",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(AlertDialog.this, "왜 닫냐?!!", Toast.LENGTH_SHORT).show(); //무명 내부 클래스이므로 AlertDialog.this로 해야 한다. } }); ad.show(); }else{ Toast.makeText(this, "배고프지용!!", Toast.LENGTH_SHORT).show(); } } }