Implementation of the OnClick event for Android development

Source: Internet
Author: User

From the beginning of 2015 to learn Android development, now the OnClick event implementation written down, recorded, for reference.

Implement button click Function, let TextView display a line of text, the simplest onclick event.

Direct Sticker Code:

     Public void Onclick_method (view view) {        String contextstring= "Click on this button to achieve the click function";        TextView TextView=(TextView) Findviewbyid (R.ID.TESTTV);        Textview.settext (contextstring);           }

Layout file:

    <TextViewAndroid:id= "@+id/testtv"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "@string/hello_world"/>    <ButtonAndroid:onclick= "Onclick_method"Android:id= "@+id/button"Android:layout_below= "@id/testtv"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "click"        />

Take a look at the following implementations:

Before clicking:

After clicking:

See there are other ways, but I feel this is the most simple and clear, later development and use of this can be.

Implementation of the OnClick event for Android development

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.