Using toast in an activity

Source: Internet
Author: User

Toast is mainly used to set a pop-up reminder window!

is when you click a button, you can pop up a prompt window.

We can add code in the OnCreate method:

Button button1= (button) Findviewbyid (r.id.button_1)//is to get the instance of the button

Button1.setonclicklistener () {//Set up a listener by calling the Setonclicklistener () method

@override

public void OnClick (View v)

Toast.maketext (Firstactivity.this, "You click Button 1",//firstactivity refers to the address of the toast activity to be passed in, "XXXX" is the content of the toast incoming;

Toast.length_short). Show ();//length_short refers to the length of the toast display;

}

Button1 is an instance of a button, because Findview gets a view object and we want to convert it to a button object;

Button_1 refers to the ID of the button;

When the listener is set, the OnClick method in the listener is executed when the button is clicked. Therefore, the ability to eject a toast is written in the onclick () method.

Using toast in an activity

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.