Android AlertDialog onClick未调用
我的应用程序中有一个奇怪的问题 让我解释一下。。。 我有一个列表视图,其中显示了几个项目。 当我点击其中一个项目时,我会显示一个带有“是”和“否”按钮的alertDialog。 该警报显示良好,当我单击其中一个按钮时,将调用onclick处理程序并执行我的代码。 到目前为止还好吧 但是当我离开这个视图(返回)并开始一些其他活动时,然后返回到这个视图。 我可以在列表中选择一个项目,会显示alertDialog,但当我单击一个按钮时,什么也不会发生。 它没有进入我的onClick方法 这太奇怪了,我尝试了不同的技术来显示alertDialog并捕捉事件,但每次我都遇到同样的问题。 我在logcat中没有转储或日志 下面是我如何调用AlertDialog的代码Android AlertDialog onClick未调用,android,android-alertdialog,onclicklistener,Android,Android Alertdialog,Onclicklistener,我的应用程序中有一个奇怪的问题 让我解释一下。。。 我有一个列表视图,其中显示了几个项目。 当我点击其中一个项目时,我会显示一个带有“是”和“否”按钮的alertDialog。 该警报显示良好,当我单击其中一个按钮时,将调用onclick处理程序并执行我的代码。 到目前为止还好吧 但是当我离开这个视图(返回)并开始一些其他活动时,然后返回到这个视图。 我可以在列表中选择一个项目,会显示alertDialog,但当我单击一个按钮时,什么也不会发生。 它没有进入我的onClick方法 这太奇怪了,我
public void onListItemClick(ListView l, View v, int position, long id) {
cancelAppointment(position);
}
public void cancelAppointment(int position){
selectedPosition = position;
Util.getInstance().setApptToDelete(appointmentsArray.get(position));
askConfirmation();
}
public void askConfirmation(){
String message = "Are you sure you want to cancel this appointment?";
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setMessage(message);
alertbox.setPositiveButton("Yes", this);
alertbox.setNegativeButton("No", this);
AlertDialog ald = alertbox.create();
ald.show();
//alertbox.show();
}
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
if(which == -2){
// no
dialog.cancel();
}else{
// yes
dialog.cancel();
if(Util.getInstance().getCreateBookingResult() != 0){
new CancelAppointment().execute("");
pb.setVisibility(View.VISIBLE);
}
}
}
有人知道这个错误吗?更重要的是,知道如何修复它吗
谢谢各位
非常感谢您的任何帮助。您的
AlertDialog
和onClickListener
是正确的。它与代码中的其他内容有关。也许发布完整的类或更好的,压缩您的项目,并上传到某个地方,我们可以下载它,并尝试它。这可能与您的ListView
实现有关。