• [안드로이드] 안드로이드 대화상자(AlertDialog)를 만져보자2012.11.10 PM 07:57

게시물 주소 FONT글자 작게하기 글자 키우기



버튼을 누르면 대화 상자를 출력하는 앱을 만들기 위해
버튼하나를 포함하는 xml을 만들어주세요.



package com.example.alertdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.oncl-ckListener;
import android.widget.Button;

public class MainActivity extends Activity {

private static final int DIALOG_YES_NO_MESSAGE = 1;

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_YES_NO_MESSAGE :
AlertDialog.Builder builer = new AlertDialog.Builder(this);
builer.setTitle("타이틀 부분").setMessage("중간 메시지")
.setPositiveButton("Yes",
new DialogInterface.oncl-ckListener() {
public void oncl-ck(DialogInterface dialog, int whichButton) {
// TODO Auto-generated method stub
MainActivity.this.finish();
}
}).setNegativeButton("No",
new DialogInterface.oncl-ckListener() {

public void oncl-ck(DialogInterface dialog, int whichButton) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
//대화 상자 객체 생성
AlertDialog alert = builer.create();
return alert;
}
return null;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b = (Button)findViewById(R.id.button1);
b.setoncl-ckListener(new oncl-ckListener() {
public void oncl-ck(View v) {
// TODO Auto-generated method stub
showDialog(DIALOG_YES_NO_MESSAGE);
}
});
}
}



버튼을 클릭하면 대화상자가 나옵니다.
댓글 : 0 개
친구글 비밀글 댓글 쓰기