package com.example.wang.testapp2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ZuoyeActivity
extends AppCompatActivity {
TextView textView;
Button bt0;
Button bt1;
Button bt2;
Button bt3;
Button bt4;
Button bt5;
Button bt6;
Button bt7;
Button bt8;
Button bt9;
Button btjia;
Button btjian;
Button btx;
Button btchu;
Button btdian;
Button btC;
Button btDEL;
Button btdengyu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zuoye);
textView=
(TextView)findViewById(R.id.tv_1);
bt0=
(Button)findViewById(R.id.bt0);
bt1=
(Button)findViewById(R.id.bt1);
bt2=
(Button)findViewById(R.id.bt2);
bt3=
(Button)findViewById(R.id.bt3);
bt4=
(Button)findViewById(R.id.bt4);
bt5=
(Button)findViewById(R.id.bt5);
bt6=
(Button)findViewById(R.id.bt6);
bt7=
(Button)findViewById(R.id.bt7);
bt8=
(Button)findViewById(R.id.bt8);
bt9=
(Button)findViewById(R.id.bt9);
btjia=
(Button)findViewById(R.id.btjia);
btjian=
(Button)findViewById(R.id.btjian);
btx=
(Button)findViewById(R.id.btx);
btchu=
(Button)findViewById(R.id.btchu);
btdian=
(Button)findViewById(R.id.btdian);
btdengyu=
(Button)findViewById(R.id.btdengyu);
btC=
(Button)findViewById(R.id.btC);
btDEL=
(Button)findViewById(R.id.btDEL);
bt_OnClickListener bt_1=
new bt_OnClickListener();
bt0.setOnClickListener(bt_1);
bt1.setOnClickListener(bt_1);
bt2.setOnClickListener(bt_1);
bt3.setOnClickListener(bt_1);
bt4.setOnClickListener(bt_1);
bt5.setOnClickListener(bt_1);
bt6.setOnClickListener(bt_1);
bt7.setOnClickListener(bt_1);
bt8.setOnClickListener(bt_1);
bt9.setOnClickListener(bt_1);
btjia.setOnClickListener(bt_1);
btjian.setOnClickListener(bt_1);
btx.setOnClickListener(bt_1);
btchu.setOnClickListener(bt_1);
btdengyu.setOnClickListener(bt_1);
btdian.setOnClickListener(bt_1);
btC.setOnClickListener(bt_1);
btDEL.setOnClickListener(bt_1);
}
class bt_OnClickListener
implements View.OnClickListener
{
@Override
public void onClick(View v) {
Button bt=
(Button)v;
String str=
bt.getText().toString();
textView.setText(str);
}
}
}
ZuoyeActivity
<?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.example.wang.testapp2.ZuoyeActivity"
android:rowCount="6"
android:columnCount="4">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_columnSpan="4"
android:layout_rowWeight="8"
android:id="@+id/tv_1"
android:textSize="40sp"
android:paddingRight="10dp"
android:background="#ccc"
android:gravity="right|center_vertical"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:layout_rowWeight="1"
android:id="@+id/btC"
android:textSize="25sp"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEL"
android:id="@+id/btDEL"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="÷"
android:id="@+id/btchu"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x"
android:id="@+id/btx"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/bt7"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/bt8"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/bt9"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/btjian"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/bt4"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/bt5"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/bt6"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/btjia"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/bt1"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/bt2"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/bt3"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:id="@+id/btdengyu"
android:textSize="25sp"
android:layout_columnWeight="1"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:layout_gravity="fill"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/bt0"
android:textSize="25sp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_columnSpan="2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/btdian"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
</GridLayout>
activity_zuoye
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wang.testapp2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ZuoyeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"></activity>
</application>
</manifest>
AndroidManifest
转载于:https://www.cnblogs.com/wangchuanqi/p/5455661.html
转载请注明原文地址: https://mac.8miu.com/read-16254.html