我在一个简单的类中创建了一个警报框,但我不知道问题出在哪里。我的代码如下。当我运行我的活动并且我想运行我的 alertdialog 时,应用程序崩溃了。
private class ApplicationLauncher implements
AdapterView.OnItemClickListener {
@Override
public void onItemClick(final AdapterView parent, View v,
final int position, long id) {
// //////////////////////////////////////////////////////////
AlertDialog.Builder builder = new AlertDialog.Builder(
getApplicationContext());
builder.setCancelable(true);
builder.setTitle("TestsAuthen");
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationInfo app = (ApplicationInfo) parent
.getItemAtPosition(position);
startActivity(app.intent);
}
});
builder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
// //////////////////
}
}