2010年12月10日金曜日

AlertDialog勉強中...

まず AlertDialogを作るためのBuilderを作って
final AlertDialog.Builder builder  = new AlertDialog.Builder(this);

タイトル(っていうか表示する文字)を設定して
builder.setTitle("電話しますか?");

する場合と、しない場合のボタン表示とリスナーを設定
// 「する」場合の処理
builder.setPositiveButton("する", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});

// 「しない」場合の処理
builder.setNegativeButton("しない", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});

アラートダイヤログを生成して
AlertDialog dialog = builder.create();

表示
dialog.show();

で終わり。

0 件のコメント:

コメントを投稿