Android Development--diglog Cancel differs from dismiss method

Source: Internet
Author: User

Alertdialog the difference between dismiss and cancel methods

Alertdialog is easy to use, but one question is: what is the difference between the dismiss method and the Cancel method?

Today has the time, looked at the source code (actually the source code is not all so abstruse!) ~ ~).

Alertdialog Inheritance and dialog, now look at the structure diagram:

The implementation of the dismiss and cancel methods is then found in the dialog class. Important to see dismiss Source:

Java code
  1. Public void Cancel () {
  2.        if  (mcancelmessage != null
  3. //obtain a new message so this dialog can be re-used
  4. Message.obtain (mcancelmessage). Sendtotarget ();
  5. }
  6. Dismiss ();
  7. }

See what you got! The dismiss method was called in the Cancel method. But now there is one more question: What is Mcancelmessage?

Private Message mcancelmessage; This is a statement in the source code.

Then look at the source code:

Java code
  1. public void  Setoncancellistener (final  oncancellistener listener)  {  
  2.        if  (listener != null
  3. Mcancelmessage = Mlistenershandler.obtainmessage (CANCEL, listener);
  4. } Else {
  5. Mcancelmessage = null;
  6. }
  7. }
  8. ublic void< Span style= "color:black;" > setcancelmessage (final message msg)  {  
  9. Mcancelmessage = msg;
  10. }

Now the problem is clear, that is, if you call Setoncancellistener when creating Alertdialog, the Mcancelmessage variable has a role, otherwise dismiss and cancel are equivalent.

Android Development--diglog cancel differs from dismiss method

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.