Tips for Android messages, toast Toast Way

Source: Internet
Author: User

1: Select a control to trigger

2: Trigger event to listen, then bind Toast object for message prompt

1, when creating an Android project, bring your own activity, and we look at the code

1  PackageCom.example.androidday2testbyteacherbydfs;2 3 Importandroid.app.Activity;4 Importandroid.content.Intent;5 ImportAndroid.os.Bundle;6 ImportAndroid.view.View;7 ImportAndroid.view.View.OnClickListener;8 ImportAndroid.widget.Button;9 Ten  One  Public classMainactivityextendsActivity { A  -     PrivateButton butn; -      the @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); -         //to set the layout + Setcontentview (r.layout.mytest); -         //returns a Button control object.  +BUTN =(Button) Findviewbyid (r.id.mybuttonone); AButn.settext ("You, point me to see ..."); at            -          -         //This is an anonymous inner class that implements a click event to prompt for information.  -         /* - Butn.setonclicklistener (New Onclicklistener () { - //Create a new anonymous inner class in @Override - Public void OnClick (View arg0) { to Toast ss = Toast.maketext (Mainactivity.this, "welcome you to learn Android", Toast.length_long); + ss.show (); -                 } the             });*/ *          $         //the external class is now referenced to implement the click Information (for easy maintenance purposes)Panax Notoginseng          -Butn.setonclicklistener (NewMytestonclickone ( This)); the          +         A     } the}

It already has an implementation,-------anonymous inner class,

Look at the structure:

Now I second is the realization of the way, the external class is convenient maintenance

Create a Mytestonclickone This class implements the interface of the Click event as follows:

1  PackageCom.example.androidday2testbyteacherbydfs;2 3 4 5 Importandroid.app.Activity;6 ImportAndroid.content.Context;7 Importandroid.content.Intent;8 ImportAndroid.view.View;9 ImportAndroid.view.View.OnClickListener;Ten ImportAndroid.widget.EditText; One ImportAndroid.widget.Toast; A /** - * Build a Listener class for button click events -  * @authorAdministrator the  * -  */ -  Public classMytestonclickoneextendsActivityImplementsOnclicklistener { -  +     PrivateContext con; -      Publicmytestonclickone (Context con) { +          This. con=con; A          at     } -      - @Override -      Public voidOnClick (View arg0) { -         //build a toast that corresponds to the alert of the webpage. Maketext (Contextual context object, string string, showing the time of the delay);  -Toast ts = Toast.maketext (Con, "Welcome to your presence!"), Toast.length_long); in ts.show ();//This is open meaning, that is, the meaning of the call.  -        toIntent Intent =NewIntent (con,mytestredirectpage.class); +          - con.startactivity (intent); the          *     } ; $     Panax Notoginseng}

When a run-time effect

----------------------------------------------------------------------------------------------

The above is the full content of the toast message prompt.

Tips for Android messages, toast Toast Way

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.