9.23安卓
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 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( "" ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | <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> |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步