Android Learning Notes (i) Activity usage and listener Onclicklistener&oncheckchangedlistener

Source: Internet
Author: User

Use of 1.Activity

When creating an Android project with Eclipse, there is a default XML file Activity_main in the Res/layout directory, where you can set a static layout. In Mainactivity.java, Setcontentview (R.layout.activity_main) is called in the OnCreate method, a layout file is obtained, and an object is generated for each activity in a layout file. We want to set the activity in code, we must set the Id,findviewbyid (r.id.xx) method for activity in the layout file to get the activity we want, and we need to change it down. Once we get the activity object, we can make various settings for it.

2. Use of listeners

Process: A. Use the Findviewbyid method to get the activity object you want to listen to

B. Defining a class to implement a listener interface

C. Generate objects of this class

D. Binding listener for activity that you want to listen to

onclicklistner:public void OnClick (view v) View V represents the activity that triggered the click event, passing the object to the OnClick method, via V.getid () You can tell which activity triggered the event.

Oncheckchangedlistener: For checkbox, checked or unchecked will trigger public void oncheckedchanged (Compoundbutton Buttonview, Boolean isChecked) Boolean variable isChecked can be used to determine whether a check is selected.

Android Learning Notes (i) Activity usage and listener Onclicklistener&oncheckchangedlistener

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.