Android Re-learning

Source: Internet
Author: User

1. Click on the event to achieve several ways

  

        Button Btn1 = (button) Findviewbyid (R.id.button1); // Get button Resource             Btn1.setonclicklistener (new Button.onclicklistener () {//Create a listener for this button , Create an instance  of Button.onclicklistener this class public void  OnClick (View v) {// If there is a button operation,        execute onclick= "click Button01";           Ev1.settext (strtmp); Eject strtmp           }  

The second method:

In component file Main.xml, add to button:

android:onclick= "Onclick_event"

Add the following code to the activity:

public void onclick_event (view view) {
TextView TextView = (TextView) Findviewbyid (R.ID.TEXTVIEW1);
Textview.settext ("You clicked Button");
}

The role of parameters in 2.oncreate

Super. OnCreate (savedinstancestate);

In the activity life cycle, as long as you leave the visible phase, or lose focus, theactivity is likely to be terminated by the process! , was killed, , at this time, there is a mechanism, can save the state of the moment, this is the role of Savedinstancestate, in short, is to save the activity before the interface.

Setcontentview (R.layout.activity_main);

Loads the UI component from the Res/layout/activity_main.xml file.

3.

ImageView ImageView = (ImageView) Findviewbyid (R.id.myimageview);

Gets the button in the XML in the activity, the parameter is the ID of the button

Android Re-learning

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.