• 第五周


    package com.example.test3;
     
    import android.app.AliasActivity;
    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
      
      
      
    public class MainActivity extends AliasActivity{
      
        double num1 = 0 , num2 = 0 , result = 0;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
      
        }
      
        public void click(View v){
      
            EditText et1 = (EditText) findViewById(R.id.et1);
            EditText et2 = (EditText) findViewById(R.id.et2);
      
      
            num1 = Double.parseDouble(et1.getText().toString());
            num2 = Double.parseDouble(et2.getText().toString());
      
            switch (v.getId())
            {
                case R.id.btn1:
                    result = num1 + num2;
                    break;
                case R.id.btn2:
                    result = num1 - num2;
                    break;
                case R.id.btn3:
                    result = num1 * num2;
                    break;
                case R.id.btn4:
                    result = num1 / num2;
                    break;
            }
      
        }
      
      
        public void click1(View v){
      
            TextView tv1 = (TextView) findViewById(R.id.tv);
      
                /* @setProgress 设置初始进度
                 * @setProgressStyle 设置样式(水平进度条)
                 * @setMax 设置进度最大值
                 */
                final int Max = 100;
                final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setProgress(0);
                progressDialog.setTitle("正在计算,请稍等...");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                progressDialog.setMax(Max);
                progressDialog.show();
                /**
                 * 开个线程
                 */
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        int p = 0;
                        while (p <= Max){
                            try {
                                Thread.sleep(10);
                                p++;
                                progressDialog.setProgress(p);
                            }catch (Exception e){
                                e.printStackTrace();
                            }
                        }
                        progressDialog.cancel();//达到最大就消失
                    }
      
                }).start();
      
            tv1.setText("计算结果:" + result + "");
      
        }
      
        public void click2(View v){
            EditText et1 = (EditText) findViewById(R.id.et1);
            EditText et2 = (EditText) findViewById(R.id.et2);
            TextView tv = (TextView) findViewById(R.id.tv);
            et1.setText("");
            et2.setText("");
            tv.setText("");
        }
      
    }
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#786678" >
     
        <EditText
            android:id="@+id/et1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
     
        <EditText
            android:id="@+id/et2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/et1" />
     
        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/et2"
            android:onClick="click"
            android:text="+" />
     
        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/et2"
            android:layout_toRightOf="@id/btn1"
            android:onClick="click"
            android:text="-" />
     
        <Button
            android:id="@+id/btn3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/et2"
            android:layout_toRightOf="@id/btn2"
            android:onClick="click"
            android:text="*" />
     
        <Button
            android:id="@+id/btn4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/et2"
            android:layout_toRightOf="@id/btn3"
            android:onClick="click"
            android:text="/" />
     
        <Button
            android:id="@+id/btn5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn1"
            android:layout_marginLeft="20dp"
            android:background="#895865"
            android:onClick="click1"
            android:text="计算"
            android:textColor="#024488" />
     
        <Button
            android:id="@+id/btn6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn4"
            android:layout_marginLeft="135dp"
            android:layout_toRightOf="@id/btn5"
            android:background="#895865"
            android:onClick="click2"
            android:text="清空"
            android:textColor="#024488" />
     
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/btn5"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:text="计算结果:" />
     
    </RelativeLayout>
  • 相关阅读:
    Unittest单元测试
    关于压力机设备的一些题
    原生 JS 实现 HTML 转 Markdown ,(html2md.js 或 html2markdown.js)
    【滚动更新】C++ 八股文选集(没代码,纯应试)
    【Example】C++ STL 常用容器概述
    权限接口写法
    使用vuecli3创建项目
    vue通过路由控制来实现的权限管理
    【更新中】程序设计实习笔记
    kserve predict api v2
  • 原文地址:https://www.cnblogs.com/z118127/p/14126955.html
Copyright © 2020-2023  润新知