20160706 Key Control text

Source: Internet
Author: User

 PackageCom.example.xiaolan01;ImportAndroid.graphics.Color;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {TextView tex1,tex2;//defines two names, which point to the TextView control;Button Bt1,bt2;//define two names, a control that points to a button    Charb; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Tex1= (TextView) Findviewbyid (R.id.textview);//bind the Tex1 and ID textview text together;Tex2 = (TextView) Findviewbyid (R.ID.TEXTVIEW2);//bind the Tex2 and ID textview2 text together;BT1 = (Button) Findviewbyid (R.id.button);//bind the BT1 with the text with the ID button;BT2 = (Button) Findviewbyid (R.id.button2);//bind the BT2 and ID button2 text together;Tex1.settext ("Text 1");//change the text of the control that Tex1 points to,Tex1.settextcolor (Color.green);//change the color that tex1 points to,Tex2.settext ("Text 2");//change the text of the control that Tex2 points to,Tex2.settextcolor (Color.Blue);//change the color that tex2 points to,Bt1.settext ("Key 1");//change the text of the control that bt1 points to,Bt1.settextcolor (Color.cyan);//change the color that bt1 points to,Bt2.settext ("Key 2");//change the text of the control that BT2 points to,Bt2.settextcolor (Color.yellow);//change the color that bt2 points to,Bt1.setonclicklistener (Listener1);//Create a listener for BT1Bt2.setonclicklistener (LISTENER2);//Create a listener for BT2A=0; b=0; }    //implementing the Button1 listenerButton.onclicklistener Listener1 =NewButton.onclicklistener () {//Creating Listener Objects         Public voidOnClick (View v) {if(a==0)            {                //What needs to be done in the listener .Tex1.settext ("Key 1 is pressed"); A=1; }          Else{Tex1.settext (""); A=0;    }        }    }; //implementing the Button2 listenerButton.onclicklistener Listener2 =NewButton.onclicklistener () {//Creating Listener Objects         Public voidOnClick (View v) {if(b==0)            {                //What needs to be done in the listener .Tex2.settext ("Key 2 has been pressed"); b=1; }            Else{Tex2.settext (""); b=0; }        }    };}

20160706 Key Control text

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.