gpt4 book ai didi

android - 当我单击项目时不显示警报对话框?

转载 作者:行者123 更新时间:2023-11-29 02:10:25 24 4
gpt4 key购买 nike

我想在点击 pdfimage 时显示警告对话框,我尝试使用以下代码但不显示 alertdialogue 。

private OnItemClickListener itemClickListener=new OnItemClickListener() {
@SuppressWarnings("rawtypes")
public void onItemClick(AdapterView parent, View arg1, int position, long arg3) {
int i=position;
pdf=pdfarray[i];
/*******************************/
AlertDialog.Builder builder = new AlertDialog.Builder(ImageShowActivity.this);
final AlertDialog alert = builder.create();
builder.setMessage("Are you sure you want to exit?")
.setNeutralButton("Cancel",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id) {
alert.dismiss();
}
})
.setPositiveButton("Download", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent=new Intent(ImageShowActivity.this,OpenPDFNew.class);
intent.putExtra("pdfurl",pdf );
startActivity(intent);
}
})
.setNegativeButton("Online", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
alert.show();
/****************************************/
}
};

最佳答案

你在声明alert Builder的内容之前调用了builder.create(),你应该在像这样创建内容之后调用builder.create()

AlertDialog.Builder builder = new AlertDialog.Builder(Activity_name.this);
builder.setItems(items, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int position) {
.........
}
}
});
builder.create().show();

关于android - 当我单击项目时不显示警报对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7821736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com