<?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