亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

Android實(shí)現(xiàn)兩個數(shù)相加功能

瀏覽:67日期:2022-09-25 10:39:59

本文實(shí)例為大家分享了Android實(shí)現(xiàn)兩個數(shù)相加的具體代碼,供大家參考,具體內(nèi)容如下

要實(shí)現(xiàn)如圖所示的加法計(jì)算器的話,還是比較簡單的,下面直接上demo,有不懂的可以留言交流。

Android實(shí)現(xiàn)兩個數(shù)相加功能

1、下面是activity.xml的布局文件

<?xml version='1.0' encoding='utf-8'?> <LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' tools:context='.MainActivity'> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='請輸入整數(shù)x:'/> <EditText android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:ems='20'/> </LinearLayout> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='請輸入整數(shù)y:'/> <EditText android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:ems='20'/> </LinearLayout> <Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_gravity='center' android:text='確認(rèn)'/> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text=' x+y=:'/> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:textColor='#0aaaaa' android:ems='20'/> </LinearLayout></LinearLayout>

2、下面是MainActivity.java的代碼

package com.example.hjw.calculator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends AppCompatActivity { private TextView tv1,tv2; private EditText edt1,edt2; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn=(Button)this.findViewById(R.id.btn); edt1=(EditText)this.findViewById(R.id.edit1); edt2=(EditText)this.findViewById(R.id.edit2); tv1=(TextView)this.findViewById(R.id.text1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String inputText1=edt1.getText().toString(); String inputText2=edt2.getText().toString(); int num1=Integer.valueOf(inputText1).intValue(); int num2=Integer.valueOf(inputText2).intValue(); num1=num1+num2; inputText1=String.valueOf(num1); tv1.setText(inputText1); } }); }}

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

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

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: yy9299国产精品视频 | 特黄特级a级黄毛片免费观看多人 | 欧美韩国日本在线 | 极品精品国产超清自在线观看 | 久久夜色tv网站免费影院 | 久草手机在线观看视频 | 婷婷丁香久久 | 久久99视频 | 久久久久亚洲 | 黄色三级视频在线观看 | 99热精品国产三级在线观看 | 色婷婷在线播放 | 国产成人精品免费视 | 亚洲欧美日韩国产 | 久草久爱 | 国产精品视频牛仔裤一区 | 久久夜色精品国产尤物 | 免费特黄视频 | 欧美成人免费一区在线播放 | 免费国产成高清人在线视频 | 成人春色在线观看免费网站 | 国产精品αv在线观看 | chinese在线播放91国内 | 在线免费观看精品 | 国产精品美女福利视频一区 | 午夜精品久久久久久久第一页 | 在线va| 黄色一级片免费播放 | 日韩毛片网站 | 国语精品视频在线观看不卡 | 日本一区二区三区有限公司 | 亚欧洲精品在线视频免费观看 | 免费性生活网站 | 久久精品一区二区 | 亚洲乱码一二三四区国产 | 深夜福利视频在线看免费 | 亚洲免费色视频 | 五月狠狠亚洲小说专区 | 欧美三级大片在线观看 | 国产亚洲欧美另类一区二区三区 | 欧美a级片视频 |