正如标题所说,当我将.setButton放入警报对话框时,我的应用程序崩溃了。 有什么问题,我应该如何解决?
button_fs = (Button) findViewById(R.id.button_fs);
final AlertDialog adfs = new AlertDialog.Builder(this).create();
button_fs.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
adfs.setTitle("Meraxes");
adfs.setMessage("What would you like to do?");
adfs.setButton(1, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Aww yiss", Toast.LENGTH_SHORT).show();
}
});
adfs.setButton(2, "cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "you have pressed cancel", Toast.LENGTH_SHORT).show();
}
});
adfs.show();
}
});