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

您的位置:首頁技術(shù)文章
文章詳情頁

android簡易計算器的制作

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

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

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

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

//第一個數(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' /> //標(biāo)題 <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='丑陋的而且只能算加減乘除的計算機(jī)' 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寫四個按鈕對應(yīng)的方法,代碼如下:

//加法 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.看似代碼很長,其實(shí)都是一樣的,很簡單就完成了,其中MainActivity.java中的代碼我沒有給出注釋,就是幾種類型的轉(zhuǎn)換。歡迎大佬指點(diǎn),初學(xué)者不懂的可以給我留言。下面給出仿真機(jī)運(yùn)行效果。

android簡易計算器的制作

android簡易計算器的制作

更多計算器功能實(shí)現(xiàn),請點(diǎn)擊專題: 計算器功能匯總 進(jìn)行學(xué)習(xí)

關(guān)于Android計算器功能的實(shí)現(xiàn),查看專題:Android計算器 進(jìn)行學(xué)習(xí)。

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

標(biāo)簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产精品多人| 成人精品视频| 日韩精品一二三| 亚洲视频二区| 国产精品天堂蜜av在线播放| 在线观看亚洲精品福利片| 亚洲啊v在线免费视频| 国产精选久久| 四季av一区二区凹凸精品| а√在线中文在线新版| 激情自拍一区| 日本不卡视频在线观看| 久久久国产精品网站| 91精品一区二区三区综合在线爱| 日韩视频在线一区二区三区 | 麻豆中文一区二区| 欧美xxxx性| 精品色999| 精品久久97| 激情婷婷久久| 国产日韩欧美| 国产一区日韩一区| 97久久精品| 久久精品导航| 日本不卡高清| 久久蜜桃资源一区二区老牛| 久久亚洲风情| 老司机精品视频网| 久久久久中文| 国产毛片久久久| 99免费精品| 国产日韩一区二区三区在线| 99久久激情| 综合欧美精品| 国产精品99视频| 水蜜桃久久夜色精品一区的特点 | 亚洲大全视频| 国产精品一区二区三区www| 狠狠久久伊人中文字幕| 免费在线观看一区二区三区| 成人在线观看免费视频| 免播放器亚洲一区| 久久97久久97精品免视看秋霞| 国产精品一级| 国产99久久| 精品一区电影| 日韩精品一区第一页| 成人一区而且| 日韩精选在线| 午夜久久影院| 中文字幕高清在线播放| 日韩国产一区二| 亚洲电影在线| 国内揄拍国内精品久久| 日本一区二区三区视频在线看 | 久久精品国产99| 亚洲资源av| 日韩一区二区三区免费播放| 蜜臀av在线播放一区二区三区 | 久久精品 人人爱| 国产偷自视频区视频一区二区| 精品欠久久久中文字幕加勒比| 亚洲+小说+欧美+激情+另类| 国产二区精品| 欧洲在线一区| 国产66精品| 老牛国内精品亚洲成av人片| 欧美日韩1区| 天堂精品久久久久| 丝袜诱惑制服诱惑色一区在线观看 | 成人在线视频免费| 久久国内精品自在自线400部| 欧美一级专区| 91久久国产| 999精品一区| 日本美女一区| 成人羞羞在线观看网站| 欧美黑人做爰爽爽爽| 日本视频中文字幕一区二区三区| 国产精品婷婷| 午夜影院欧美| 国产主播一区| 999久久久精品国产| 鲁鲁在线中文| 国产精品黑丝在线播放| 不卡专区在线| av高清不卡| 久久久成人网| 欧美日韩国产一区二区三区不卡| 久久久久久黄| 国产综合色区在线观看| 日韩欧美中文| 中文字幕亚洲精品乱码| 欧美在线亚洲综合一区| 亚洲欧美一区在线| 91精品婷婷色在线观看| 超碰在线99| 91tv亚洲精品香蕉国产一区| 日本精品影院| 亚洲1234区| 午夜欧美精品久久久久久久| 麻豆91精品| 日韩高清一级| 国产精品综合| 国产videos久久| 99久久精品国产亚洲精品| www.51av欧美视频| 日本久久综合| se01亚洲视频| 成人污污视频| 高清精品久久| 正在播放日韩精品| 精品久久一区| 久久只有精品| 久久99蜜桃| 欧美aaaaaa午夜精品| 国产日韩一区二区三区在线| 午夜亚洲福利| 亚洲三区欧美一区国产二区| 欧美综合国产| 蜜乳av另类精品一区二区| 好吊一区二区三区| 色在线中文字幕| 麻豆成人91精品二区三区| 亚州欧美在线| 日韩一二三区在线观看| 日本精品在线播放| 国产亚洲一区二区三区啪| 国产日韩欧美三级| 欧美国产视频| 日本一区二区高清不卡| 久久超碰99| 国产精品一区二区三区四区在线观看| 日韩av一二三| 国产剧情一区| 国产成人77亚洲精品www| 国产高清不卡| 日韩欧美精品一区| 美女精品一区二区| 欧美日韩在线观看首页| 久久视频精品| 中国女人久久久| 亚洲欧美综合| 亚洲一区二区毛片| 日韩中文av| 国产精品视频一区视频二区| 精品亚洲二区| 免费一二一二在线视频| 高清一区二区三区| 久久精品女人| 国产aⅴ精品一区二区三区久久| 日韩一区二区三免费高清在线观看 | 99精品小视频| 日韩视频不卡| 97久久亚洲| 黑森林国产精品av| 九九在线精品| 亚洲乱码久久| 久久精品伊人| 激情五月综合网| 1024精品一区二区三区| 久久最新视频| 国产精品久久久久77777丨| 成人在线视频免费看| 久久伦理在线| 69堂精品视频在线播放| 91亚洲无吗| 国产一区二区三区四区二区| 亚洲不卡av不卡一区二区| 亚洲一二三区视频| 国产日产高清欧美一区二区三区 | 精品久久美女| 日韩视频在线一区二区三区| 日韩avvvv在线播放| 伊人久久av| 亚洲精品麻豆| 伊人久久在线| 日本麻豆一区二区三区视频| 亚洲伦乱视频| 日本va欧美va精品发布| 欧美久久天堂| 蜜桃久久久久久久| 97精品国产福利一区二区三区| 五月天综合网站| 国产探花在线精品| 蜜臀国产一区| 97精品久久| 天堂网在线观看国产精品| 免费日韩成人| 一区二区国产精品| 日韩一区亚洲二区| 中文字幕一区二区三区日韩精品| 麻豆国产欧美日韩综合精品二区| 免费视频亚洲| 国产中文欧美日韩在线| 亚洲aⅴ网站| 狠狠色狠狠色综合日日tαg| 国产一区二区精品久| 日本一区免费网站| 日韩电影免费网站|