zoukankan      html  css  js  c++  java
  • 第五周

    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>
  • 相关阅读:
    poj 1789 每个字符串不同的字母数代表两个结点间的权值 (MST)
    poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题
    poj 1631 最多能有多少条不交叉的线 最大非降子序列 (LIS)
    hdu 5256 最少修改多少个数 能使原数列严格递增 (LIS)
    hdu 1025 上面n个点与下面n个点对应连线 求最多能连有多少条不相交的线 (LIS)
    Gym 100512F Funny Game (博弈+数论)
    UVa 12714 Two Points Revisited (水题,计算几何)
    UVa 12717 Fiasco (BFS模拟)
    UVa 12718 Dromicpalin Substrings (暴力)
    UVa 12716 && UVaLive 6657 GCD XOR (数论)
  • 原文地址:https://www.cnblogs.com/z118127/p/14126955.html
Copyright © 2011-2022 走看看