Two main forms of onClick events in Android development: androidonclick

Source: Internet
Author: User

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.

Related Article

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.