日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

android簡易計算器的制作

瀏覽:22日期:2022-09-23 09:57:31

之前有好好完成老師留過的C++大作業(yè),使用MFC制作通訊錄。所以用AS寫一個安卓的計算器并不是很難,但還是想上手操作一下,寫一個只有簡單加減乘除運算的小計算器,后面可能會考慮加一些其他的稍微復雜的計算功能。下面是步驟。

1.首先創(chuàng)建一個empty activity,取名為MyStudyCalculator。

2.打開activity_main.xml文件,創(chuàng)建兩個編輯框(EditText)、四個按鈕(Button)、一個文本框(TextView),并設置相應的id。其中編輯框作用是讓用戶填入兩個數(shù)字,四個按鈕分別對應四種不同的運算(需要對按鈕分別添加響應事件),文本框用于顯示運算結果。我另外添加了兩個文本框,一個用于顯示標題,一個顯示作者,對于該計算器來說沒有任何作用。下面給出代碼:

//第一個數(shù)字 <EditText android: android:layout_width='85dp' android:layout_height='wrap_content' android:layout_marginEnd='56dp' android:layout_marginStart='8dp' android:layout_marginTop='168dp' android:hint='@string/num1' app:layout_constraintEnd_toStartOf='@+id/second' app:layout_constraintHorizontal_bias='0.621' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' /> //第二個數(shù)字 <EditText android: android:layout_width='85dp' android:layout_height='wrap_content' android:layout_marginEnd='64dp' android:layout_marginTop='168dp' android:hint='@string/num2' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintTop_toTopOf='parent' /> //第二個數(shù)字 <TextView android: android:layout_width='96dp' android:layout_height='33dp' android:layout_marginBottom='84dp' android:layout_marginEnd='8dp' android:layout_marginStart='8dp' android:gravity='center' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.481' app:layout_constraintStart_toStartOf='parent' /> //加法按鈕 <Button android: android:layout_width='50dp' android:layout_height='50dp' android:layout_marginEnd='8dp' android:layout_marginStart='8dp' android:layout_marginTop='260dp' android:onClick='SUM' android:text='+' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.391' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' /> //減法按鈕 <Button android: android:layout_width='50dp' android:layout_height='50dp' android:layout_marginBottom='30dp' android:layout_marginEnd='148dp' android:layout_marginTop='8dp' android:onClick='SUB' android:text='-' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintTop_toTopOf='parent' app:layout_constraintVertical_bias='0.595' /> //乘法按鈕 <Button android: android:layout_width='50dp' android:layout_height='50dp' android:layout_marginBottom='152dp' android:layout_marginEnd='8dp' android:layout_marginStart='8dp' android:onClick='MUL' android:text='*' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.393' app:layout_constraintStart_toStartOf='parent' /> //除法按鈕 <Button android: android:layout_width='50dp' android:layout_height='50dp' android:layout_marginBottom='8dp' android:layout_marginEnd='148dp' android:layout_marginTop='8dp' android:onClick='DIV' android:text='/' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintTop_toTopOf='parent' app:layout_constraintVertical_bias='0.678' /> //標題 <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginEnd='8dp' android:layout_marginStart='8dp' android:layout_marginTop='36dp' android:text='丑陋的而且只能算加減乘除的計算機' android:textSize='20dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' /> //作者 <TextView android: android:layout_width='wrap_content' android:layout_height='11dp' android:layout_marginEnd='8dp' android:layout_marginStart='8dp' android:layout_marginTop='496dp' android:text='TimberWolf' android:textSize='10dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.99' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' />

3.打開MainActivity.java寫四個按鈕對應的方法,代碼如下:

//加法 public void SUM(View view) { EditText first = (EditText)findViewById(R.id.first); EditText second = (EditText)findViewById(R.id.second); TextView res = (TextView)findViewById(R.id.res); double num1 = 0; double num2 = 0; double ans = 0; String numfirst = first.getText().toString(); String numsecond = second.getText().toString(); num1 = Double.parseDouble(numfirst); num2 = Double.parseDouble(numsecond); ans = num1 + num2; res.setText(String.valueOf(ans)); } //減法 public void SUB(View view) { EditText first = (EditText)findViewById(R.id.first); EditText second = (EditText)findViewById(R.id.second); TextView res = (TextView)findViewById(R.id.res); double num1 = 0; double num2 = 0; double ans = 0; String numfirst = first.getText().toString(); String numsecond = second.getText().toString(); num1 = Double.parseDouble(numfirst); num2 = Double.parseDouble(numsecond); ans = num1 - num2; res.setText(String.valueOf(ans)); } //乘法 public void MUL(View view) { EditText first = (EditText)findViewById(R.id.first); EditText second = (EditText)findViewById(R.id.second); TextView res = (TextView)findViewById(R.id.res); double num1 = 0; double num2 = 0; double ans = 0; String numfirst = first.getText().toString(); String numsecond = second.getText().toString(); num1 = Double.parseDouble(numfirst); num2 = Double.parseDouble(numsecond); ans = num1 * num2; res.setText(String.valueOf(ans)); } //除法 public void DIV(View view) { EditText first = (EditText)findViewById(R.id.first); EditText second = (EditText)findViewById(R.id.second); TextView res = (TextView)findViewById(R.id.res); double num1 = 0; double num2 = 0; double ans = 0; String numfirst = first.getText().toString(); String numsecond = second.getText().toString(); num1 = Double.parseDouble(numfirst); num2 = Double.parseDouble(numsecond); ans = num1 / num2; res.setText(String.valueOf(ans)); }

4.看似代碼很長,其實都是一樣的,很簡單就完成了,其中MainActivity.java中的代碼我沒有給出注釋,就是幾種類型的轉換。歡迎大佬指點,初學者不懂的可以給我留言。下面給出仿真機運行效果。

android簡易計算器的制作

android簡易計算器的制作

更多計算器功能實現(xiàn),請點擊專題: 計算器功能匯總 進行學習

關于Android計算器功能的實現(xiàn),查看專題:Android計算器 進行學習。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
99精品在线观看| 精品视频一区二区三区在线观看| 蜜桃久久久久| 国产色噜噜噜91在线精品 | 亚洲午夜精品久久久久久app| 成人一区而且| 日本久久综合| 在线天堂中文资源最新版| 国产 日韩 欧美 综合 一区| 久久精品二区亚洲w码| 麻豆一区二区在线| 成人一区不卡| 欧美日韩一二| 美女久久网站| 天堂俺去俺来也www久久婷婷| 免费成人在线视频观看| 婷婷亚洲成人| 日韩午夜视频在线| 欧美亚洲国产日韩| 久久97久久97精品免视看秋霞| 精品日韩一区| 国产精品字幕| 在线视频免费在线观看一区二区| 性一交一乱一区二区洋洋av| 四虎精品永久免费| 国产精品视频首页| 国产第一亚洲| 亚洲二区视频| 热久久免费视频| 国产欧美在线观看免费| 免费看久久久| 成人精品天堂一区二区三区| 一区三区视频| 久久国产88| 欧美一区91| 精品久久视频| 99成人在线视频| 亚洲免费在线| 欧美伊人影院| 亚洲风情在线资源| 亚洲综合日本| 麻豆成人综合网| 亚洲天堂成人| 亚洲三级国产| 国产不卡一区| 男女激情视频一区| 欧美国产日本| 欧美日韩免费观看一区=区三区| 噜噜噜躁狠狠躁狠狠精品视频 | 亚洲精品影视| 欧美国产另类| 国产一区二区高清| 久久av影视| 影音先锋久久| 欧美精品第一区| 欧美69视频| 国产精品视频3p| 亚洲欧洲一区二区天堂久久| 国产精品丝袜在线播放| 欧美日韩在线网站| 日韩国产精品久久久久久亚洲| 国产精品1区在线| 亚洲精品国产偷自在线观看| 欧美欧美黄在线二区| 久久国产精品成人免费观看的软件| 亚洲毛片一区| 国产福利电影在线播放| 亚洲天堂av资源在线观看| 国产精品99在线观看| 在线亚洲自拍| 国产一区二区三区四区二区| 蜜臀久久久久久久| 久久久久一区| 国产精品伦一区二区| 国产一级久久| 女生影院久久| 亚洲ab电影| 免费国产自久久久久三四区久久 | 欧美成人一二区| 国产视频欧美| 亚洲欧洲美洲av| 国产精区一区二区| 亚洲一区成人| se01亚洲视频| 久久国产精品美女| 亚洲一区日韩在线| 日韩欧美中文| 久久精品国产久精国产| 日韩av资源网| 石原莉奈在线亚洲二区| 岛国av在线网站| 国产精品一线| 日韩专区视频网站| 亚州av乱码久久精品蜜桃| 国产精品久久观看| 国产精品久久久久9999高清| 一区二区三区国产在线| 五月精品视频| 亚洲成人va| 麻豆精品新av中文字幕| 亚洲精品观看| 蜜桃av一区| 亚洲精品网址| 精品欧美激情在线观看| 深夜福利视频一区二区| 国产a久久精品一区二区三区| 国产丝袜一区| 色狠狠一区二区三区| 亚洲综合精品四区| 一区久久精品| 最新日韩欧美| 中文亚洲免费| 欧美日韩少妇| 国产综合激情| 亚洲午夜精品久久久久久app| 国产精品色婷婷在线观看| 亚洲精选久久| 在线精品视频一区| 亚洲欧美不卡| 国产精品视区| 亚洲国产综合在线看不卡| 久久久久99| 欧美1区2区3区| 好吊日精品视频| 黄色成人精品网站| 亚洲一区二区三区四区五区午夜 | 午夜一级久久| 日韩免费看片| 免费一区二区三区在线视频| 欧美性感美女一区二区| 久久一级电影| 国产一区二区高清| 日韩欧美在线精品| 国产精品极品在线观看| 日本午夜精品久久久久| 久久久久网站| 欧美精品中文| 国产精品久久久久久久免费观看| 免费日本视频一区| 精品捆绑调教一区二区三区| 欧美日韩色图| 国产精品mm| 日韩午夜在线| 国产91久久精品一区二区| 久久久国产亚洲精品| 蜜芽一区二区三区| 天堂中文av在线资源库| 日韩av网站在线免费观看| 亚洲高清二区| 久久亚州av| 国产精品久久久网站| 欧美a级片一区| 国产欧美久久一区二区三区| 黄页网站一区| 久久久久国产一区二区| 日韩中文欧美在线| 精品国产欧美| 国产精品网址| 亚洲免费婷婷| 欧美日韩一区二区综合| 99久久婷婷| 黄色网一区二区| 羞羞答答国产精品www一本| 蜜桃精品在线| 国产精品v一区二区三区| 自由日本语亚洲人高潮| 欧美日韩一视频区二区| 亚洲精品三级| 午夜在线精品偷拍| 奇米777国产一区国产二区| 国产亚洲第一伦理第一区| 亚洲一二av| 怡红院精品视频在线观看极品| 久久国产中文字幕| 亚洲香蕉久久| 精品国产91| 日韩视频中文| 久久夜夜操妹子| 只有精品亚洲| 精品欧美日韩精品| 亚洲少妇自拍| 国产精品香蕉| 久久麻豆精品| 日韩精品91亚洲二区在线观看| 日本少妇一区| 久久夜色精品| 里番精品3d一二三区| 婷婷综合激情| 国产精品美女在线观看直播| 国户精品久久久久久久久久久不卡 | 夜鲁夜鲁夜鲁视频在线播放| 亚洲一区二区三区免费在线观看| 国产无遮挡裸体免费久久| 91精品一区二区三区综合在线爱| 综合亚洲视频| 久久久久国产一区二区| 亚洲精品观看| 久久久夜夜夜| 国产精品男女| 亚洲尤物在线|