日時: 2013/06/22 03:55 名前: lightbox
拡張子:
package com.example.basic;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.Toast;
// *********************************************************
// AlertDialog で応答する
// *********************************************************
public abstract class MessageBox {
public AlertDialog alertDialog = null;
public MessageBox(Activity context,String title,String Message) {
init(context,title,Message);
}
private void init(Activity context,String title,String Message) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(title);
alertDialogBuilder.setMessage(Message);
alertDialogBuilder.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MessageBox.this.onYesClick(dialog, which);
}
});
alertDialogBuilder.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MessageBox.this.onNoClick(dialog, which);
}
});
alertDialogBuilder.setCancelable(true);
// アラートダイアログを作成します
alertDialog = alertDialogBuilder.create();
}
public MessageBox(Activity context,String Message) {
init2(context,Message);
}
private void init2(Activity context,String Message) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle("確認");
alertDialogBuilder.setMessage(Message);
alertDialogBuilder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MessageBox.this.onYesClick(dialog, which);
}
});
alertDialogBuilder.setCancelable(true);
// アラートダイアログを作成します
alertDialog = alertDialogBuilder.create();
}
abstract void onYesClick(DialogInterface dialog, int which);
protected void onNoClick(DialogInterface dialog, int which) {
}
public void show(){
alertDialog.show();
}
}
|