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 ...