Learn the first day of Android, learn about the various layouts, then draw a button yourself and then give the button defined an event that pops up a message that says "I succeeded!" The following is the exact process:
1, modify the layout file Activity_main.xml add the following statement (I deleted the original text box)
<button android:id= "@+id/button1"
android:onclick= "Button_Click"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/hello_world"
/>
Here also to modify a file is a character file, in order to better manage the development to use the characters, Android put all the character set into a file inside, android:text= "@string/hello_world" This is the expression to use the character file in a variable "Hello_world", that is, res/values/string.xml this file with a <string name= "Hello_world" > OK </ String>
2, the above sentence android:onclick= "Button_Click" This is the event to define the response to this button, and then I added a method named "Button_Click" in Mainactivity.java,
One thing to note here is that the parameter of this method is a view-type class. This method code is given below:
public void Button_Click (View v)
{
Button temp = (button) v;
Toast.maketext (This, "I succeeded! ", Toast.length_short). Show ();
}
It says "I did it!" on the screen. "Although only to show a word, but see this sentence when very excited, finally wrote the first own Android application, although did not realize any function, hey."
Android Development Learning notes-defining events for a button