View, views component

Source: Internet
Author: User

<?xml version= "1.0" encoding= "Utf-8"?>
<gridlayout 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"
tools:context= "Com.hanqi.testapp3.MainActivity"
Android:rowcount= "5"
Android:columncount= "4"
>

<textview
Android:layout_width= "Match_parent"
android:layout_height= "50DP"
Android:layout_columnspan= "4"
Android:id= "@+id/tv_1"
android:text= "7"
Android:gravity= "Right|center_vertical"
Android:textsize= "30SP"
android:paddingright= "10DP"
Android:textcolor= "#0f0"/>
<button android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:gravity= "Center"
android:text= "7"
/>
<button android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:gravity= "Center"
android:text= "8"
/>
<button android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:gravity= "Center"
android:text= "9"
Android:id= "@+id/bt9"/>
</GridLayout>
Package com.hanqi.testapp3;

Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.TextView;

public class Mainactivity extends Appcompatactivity {
TextView tv_1;
Button Bt9;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
tv_1= (TextView) Findviewbyid (r.id.tv_1);
Event Source
bt9= (Button) Findviewbyid (R.ID.BT9);
To add a listener to the Bt9 button: 1. Anonymous inner class
Bt9.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
Business logic for handling events
Tv_1.settext ("9");
}
});
Inner class

}
public void Bt7_onclick (View v)
{
Tv_1.settext ("7");
}
public void Bt8_onclick (View v)
{
Tv_1.settext ("8");
}
public void Bt9_onclick (View v)
{
Tv_1.settext ("9");
}
}

View, views component

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.