Created
December 9, 2013 02:19
-
-
Save was0107/7866518 to your computer and use it in GitHub Desktop.
通过反射来设置对话框是否要关闭
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 通过反射来设置对话框是否要关闭,在表单校验时很管用, 因为在用户填写出错时点确定时默认Dialog会消失, 所以达不到校验的效果 | |
* 而mShowing字段就是用来控制是否要消失的,而它在Dialog中是私有变量, 所有只有通过反射去解决此问题 | |
* | |
* @param pDialog | |
* @param pIsClose | |
*/ | |
public void setAlertDialogIsClose(DialogInterface pDialog, Boolean pIsClose) { | |
try { | |
Field field = pDialog.getClass().getSuperclass() | |
.getDeclaredField("mShowing"); | |
field.setAccessible(true); | |
field.set(pDialog, pIsClose); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment