• 安卓第三次作业


    package com.example.calculator;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    import org.w3c.dom.Text;
    
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        private int i=0,n1,n2,t;//整型
        private Button sum,reduce,ride,except;
        private EditText num1,num2;
        private TextView t1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            num1 = (EditText)findViewById(R.id.nu1);
            num2 = (EditText)findViewById(R.id.nu2);
            t1 = (TextView)findViewById(R.id.end);
            sum = (Button)findViewById(R.id.sum);
            reduce = (Button)findViewById(R.id.reduce);
            ride = (Button)findViewById(R.id.ride);
            except = (Button)findViewById(R.id.except);
            sum.setOnClickListener(this);
            reduce.setOnClickListener(this);
            ride.setOnClickListener(this);
            except.setOnClickListener(this);
        }
        @Override
        public void onClick(View v){
            n1=Integer.parseInt(num1.getText().toString());
            n2=Integer.parseInt(num2.getText().toString());
            switch(v.getId()){
                case R.id.sum:
                    i = n1+n2;
                    break;
                case R.id.reduce:
                    i = n1-n2;
                    break;
                case R.id.ride:
                    i = n1*n2;
                    break;
                case R.id.except:
                    i = n1/n2;
                    break;
            }
            String a = String.valueOf(i);
            t1.setText(a);
        }
    
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#00BCD4"
            android:editable="true"
            android:gravity="center"
            android:text="Calculator"
            android:textSize="25sp" />
    
        <EditText
            android:id="@+id/time"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="true"
            android:ems="10"
            android:gravity="right"
            android:inputType="time"
            android:text="2020.9.23" />
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="true"
            android:text="第一个数" />
    
        <EditText
            android:id="@+id/nu1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:numeric="integer"/>
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:editable="true"
            android:text="第二个数" />
    
        <EditText
            android:id="@+id/nu2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:numeric="integer" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">
    
            <Button
                android:id="@+id/sum"
                android:layout_width="152dp"
                android:layout_height="wrap_content"
                android:editable="false"
                android:text="+" />
    
            <Button
                android:id="@+id/reduce"
                android:layout_width="152dp"
                android:layout_height="wrap_content"
                android:text="-"
                android:textSize="20sp" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">
    
            <Button
                android:id="@+id/ride"
                android:layout_width="152dp"
                android:layout_height="wrap_content"
                android:text="X" />
    
            <Button
                android:id="@+id/except"
                android:layout_width="152dp"
                android:layout_height="wrap_content"
                android:text="/" />
    
        </LinearLayout>
    
        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:editable="true"
            android:text="计算结果" />
    
        <TextView
            android:id="@+id/end"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp" />
    
    </LinearLayout>

  • 相关阅读:
    算法:拓扑排序
    【欧拉计划2】Even Fibonacci numbers
    机房收费系统之模版方法使用
    VC运行时库
    数据库学习(6)——基本查询操作
    Attribute与Property的区别
    记C++类成员访问权限符二三事
    大年初五去颐和园
    2013年第6周六农历除夕下午
    大年初四晚上睡前
  • 原文地址:https://www.cnblogs.com/2399301032wr/p/13739792.html
Copyright © 2020-2023  润新知