在自定义ListAdapter类中显示AlertDialog

编程入门 行业动态 更新时间:2024-10-12 05:54:48
本文介绍了在自定义ListAdapter类中显示AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很难处理在扩展BaseAdapter的Custom ListView类中显示AlertDialog的问题.

I am having a hard time dealing with displaying a AlertDialog inside a Custom ListView class which extends a BaseAdapter.

AlertDialog.Builder alertbox = new AlertDialog.Builder(getParent().getApplicationContext()); alertbox.setMessage("No Internet Connection"); alertbox.setTitle("Warning"); alertbox.setIcon(R.drawable.trn_03); alertbox.setNeutralButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { } }); alertbox.show();

上面是我正在使用的代码,而LogCat错误是

The above is the code I am using, and the LogCat error is,

06-16 11:33:25.686: ERROR/AndroidRuntime(690): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

我认为问题在于背景.我尝试了几种选择.但是没有办法.有人可以帮我吗?

I believe that the problem is because of the context. I tried a few alternative. But none works. Can anyone help me in this?.

推荐答案

对上下文进行一些细微的修改对我来说是个窍门.这是已编辑的代码段.

A slight modification with the context did teh trick for me. Here is the edited snippet.

AlertDialog.Builder alertbox = new AlertDialog.Builder(v.getRootView().getContext()); alertbox.setMessage("No Internet Connection"); alertbox.setTitle("Warning"); alertbox.setIcon(R.drawable.trn_03); alertbox.setNeutralButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { } }); alertbox.show();

更多推荐

在自定义ListAdapter类中显示AlertDialog

本文发布于:2023-11-27 20:01:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   类中   ListAdapter   AlertDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!