Two main forms of onClick events in Android development: androidonclick
The first and most common form is to add a listener for The onClick event to stimulate the event to be processed when the button is clicked. For example:
Btn1.setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubToast. makeText (MainActivity. this, "" + "by adding a listener for The onClick () event", Toast. LENGTH_LONG ). show ();}});
Second form: android: onClick =""Method for adding a response to a property.
Layout file:
<Button android: layout_width = "match_parent" android: layout_height = "wrap_content" android: onClick = "submit" android: text = "android: how to add a response method to The onClick attribute "/>
Class Code:
/*** This method is called in the layout file **/public void submit (View view) {Toast. makeText (MainActivity. this, "" + "by adding a response method for the android: onClick attribute", Toast. LENGTH_LONG ). show ();}
Tip: the second method must be declared as public, and the parameter must be of the View type; otherwise, the layout file android: onClick =""The specified method cannot be found.
Program running:
In android development, how does one implement the flying effect of an image when an onClick event is triggered?
Animation effect? You have a clear requirement.
How does android write another OnClick event in The OnClick event of the Button?
You mean the button has two onclick events.