2015年12月2日 星期三

Create an AlertDialog with custom layout/view

Reference:
http://android--code.blogspot.tw/2015/08/android-alertdialog-custom-view.html

Code snippet:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
View dialogView = getLayoutInflater().inflate(R.layout.alertdialog_custom_view,null);
builder.setView(dialogView);
builder.setTitle(R.string.dialog_title);
// Use AlertDialog default button instead of customized button
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                    ......
            }
});
builder.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ......
            }
});
builder.show();

沒有留言: