アラートダイアログ(AlertDialog)を使用するにはを読みながらalertの表示方法を勉強する。
実際に組んだのは下のプログラム
import android.app.AlertDialog;
import android.content.DialogInterface;
//thisは、ActionBarActivityをextendしたクラス
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("エラー");
builder.setMessage("入力してください。");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();実行したら確かにアラートが表示された。初めてのAndroid 第3版にも掲載されていなかったので、困っていたのだが、やり方がわかってほっとした。
初めてのAndroid 第3版
posted with amazlet at 14.09.04
Ed Burnette
オライリージャパン
売り上げランキング: 175,634
オライリージャパン
売り上げランキング: 175,634

0 コメント:
コメントを投稿