。。。 My first Android applet ...

Source: Internet
Author: User

Today to learn Android, or more happy, because this for 0 basic Android, I learn Android is more attractive!!!

Today we learned two ways to register control events (only two of them are temporarily learned):

First, directly in the Content_main.xml file, click on the "Design" button, click on the control, then in the right side of the property bar, find the OnClick property, fill in the Method name (event function names), Then in Mainacvity.java, write public void to register the event method name (view view) {... }, note: This parameter in the View view is to fill in, because this parameter is the control itself, regardless of whether the method needs to use this parameter, must add this parameter view view;

The second is to define the form control (not the trigger event button) in the Mainactivity.java class, and then implement it in the OnCreate () method, where the key code is as follows:

1 get the button on the screen.2Button button = (Button) This. Findviewbyid (r.id.login);3 //Onclicklistener is an interface4Button.setonclicklistener (NewView.onclicklistener () {5 @Override6              Public voidOnClick (View v) {7 8 9 //The following gets the value of the controlTenString name = Txtname.gettext (). toString ();//get the value inside the name input box OneString password = Txtpassword.gettext (). toString ();//get the value inside the Password input box AString message = "The name you entered is" +name+ "and the password is" +password; - //Build a Toast message, and then show it, Mainactivity.this is in which window displays the message, the length of time displayed -Toast.maketext (mainactivity. This, message, Toast.length_long). Show (); the}
Txtname,
Txtpassword This is defined in the class, defined in the class, does not need to add the final keyword, but in the OnCreate () method is defined, you need to add the final keyword, the above code, also need to put in the OnCreate () method inside

。。。 My first Android applet ...

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.