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