Android Common Controls---button

Source: Internet
Author: User

<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent"
android:layout_height= "Match_parent" android:paddingleft= "@dimen/activity_horizontal_margin"
>

<textview
Android:id= "@+id/text_view"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "First TextView"
Android:textsize= "24SP"
Android:textcolor= "#ff0000"
android:gravity= "Center"
/>

<button
Android:id= "@+id/btn1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/text_view"
Android:layout_marginbottom= "10DP"
Android:layout_centerhorizontal= "true"
android:text= "OK"/>

</RelativeLayout>

/**
* Use anonymous classes to register listeners
*/
Package com.example.uiwidgettest;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;

public class Textviewactivity extends Activity {

Private Button btn1;
Private TextView TV;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.textview);

BTN1 = (Button) Findviewbyid (R.ID.BTN1);
TV = (TextView) Findviewbyid (R.id.text_view);

    
Btn1.setonclicklistener (New View.onclicklistener () {

@Override
public void OnClick (View v) {
Switch (V.getid ()) {
Case R.id.tv:
Tv.settext ("TextView modified successfully");
Break
Default
Break
}
}
});
}
}


/**
* Implement an interface to register listeners
*/
 package com.example.uiwidgettest; 

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;

public class Textviewactivity extends Activity implements View.onclicklistener {

Private Button btn1; private TextView TV;

@Override
protected void onCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstances Tate);
Setcontentview (R.layout.textview);

Btn1 = (Button) Findviewbyid (R.ID.BTN1);
TV = (TextView) Findviewbyid (R.id.text_view);

Btn1.setonclicklistener (this);




@Override
public void OnClick (View v) {
switch (V.getid ()) {
R.ID.BTN1:
Tv.settext ("OK");
Break
Default:
break;
}
}
}

Android common Controls---button

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.