public void name() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.unit null));
builder.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "yes", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
final AlertDialog dialog = builder.create();
Button dialogButton = (Button) dialog.findViewById(R.id.i_pharmacy);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// dialog.dismiss();
}
});
dialog.show();
}
当我运行上面的代码时,我得到了 NULL 点异常。使用上面的代码在对话框上显示一个按钮。单击对话框按钮后,应该会发生一些事件。