Android development Alertdialog not disappear after clicking the button
Source: Internet
Author: User
<span id="Label3"></p><p><p>Recently there is a demand, I need the user in a pop-up box to enter a password to verify that the success of course, but if the validation fails, you need to change the Alertdialog title to "password error, please re-enter", and this alertdialog can not disappear, waiting for the user to continue to Enter.<br>So how do you implement click OK or Cancel button after dialog does not disappear?</p></p><pre class="prettyprint"><code class=" hljs cs"><span class="hljs-comment"><span class="hljs-comment">//do not Close dialog</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Try</span></span>{<span class="hljs-comment"><span class="hljs-comment">//do not close</span></span>Field field = Dialog. GetClass () . Getsuperclass (). getd Eclaredfield (<span class="hljs-string"><span class="hljs-string">"mshowing"</span></span>); Field.setaccessible (<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>); Field.<span class="hljs-keyword"><span class="hljs-keyword">Set</span></span>(dialog,<span class="hljs-keyword"><span class="hljs-keyword">false</span></span>); }<span class="hljs-keyword"><span class="hljs-keyword">Catch</span></span>(Exception E) {e.printstacktrace (); }</code></pre><p><p>yes, using the reflection mechanism in Java.<br>But then there is a problem, if I first entered the wrong password, the second I do not want to enter, I would like to back out, this time you will find that no matter what button click Can not let dialog disappear, then how to achieve when clicking the Cancel button dialog disappear?</p></p><pre class="prettyprint"><code class=" hljs cs"><span class="hljs-comment"><span class="hljs-comment">//close Dialog</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Try</span></span>{<span class="hljs-comment"><span class="hljs-comment">//off</span></span>Field field = Dialog. GetClass () . Getsuperclass (). Getdeclaredfield (<span class="hljs-string"><span class="hljs-string">"mshowing"</span></span>); Field.setaccessible (<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>); Field.<span class="hljs-keyword"><span class="hljs-keyword">Set</span></span>(dialog,<span class="hljs-keyword"><span class="hljs-keyword">true</span></span>); }<span class="hljs-keyword"><span class="hljs-keyword">Catch</span></span>(Exception E) {e.printstacktrace (); }</code></pre><p><p>That's it.</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced. If there is a wrong place, I would appreciate it if I could criticize it.</p></p> <p><p>Android development Alertdialog not disappear after clicking the button</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service