AlertDialog中setPositiveButton的疑问 在一个AlertDialog中添加setPositiveButton按钮的响应事件处理onClick,onClick默认的响应是当前这个AlertDialog消失,现在的需求是,点击setPositiveButton后当前这个AlertDialog不消失,请问怎么实现啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用反射:在你的setPositiveButton中添加://用于不关闭对话框 try { Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, false); } catch (Exception e) { e.printStackTrace(); }添加上述代码后就可以使dialog无法关闭,在你需要关闭的地方,添加://关闭对话框 try { Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, true); } catch (Exception e) { e.printStackTrace(); } 为什么不行呢我把那段try{}catch{}放在setPositiveButton中dialog还是消失了 android模拟器显示问题 Path应用 上面图片的区域,随手指下拉展示全图,怎么实现呢? ndk 关于contentprovider中的openAssetFile(Uri uri, String mode)和openFile(Uri uri, String 如何判断手机是oms还是android系统 ? 应该买哪款Android手机? android handler 同时处理多条消息 求助,Cocos2d的CCMenuItem回调方法的问题 输入法和view的冲突 Android这种左右滑动怎么做? git clone能不能用多线程? 求大牛指教,如何在软键盘弹出时 捕捉到返回键?
在你的setPositiveButton中添加:
//用于不关闭对话框
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, false);
} catch (Exception e) {
e.printStackTrace();
}添加上述代码后就可以使dialog无法关闭,在你需要关闭的地方,添加:
//关闭对话框
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
} catch (Exception e) {
e.printStackTrace();
}
我把那段try{}catch{}放在setPositiveButton中dialog还是消失了