色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

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

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

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

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

Android實(shí)現(xiàn)兩個(gè)數(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='請(qǐng)輸入整數(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='請(qǐng)輸入整數(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),請(qǐng)點(diǎn)擊專(zhuān)題: 計(jì)算器功能匯總 進(jìn)行學(xué)習(xí)

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

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 久久久久久久久久久96av | a级毛片在线免费看 | 久久精品国产只有精品6 | 欧美日韩精品一区二区另类 | 美女一级毛片免费观看 | 欧美人成在线观看 | 成人影院欧美大片免费看 | 成人精品在线观看 | 精品国产一区二区三区久久 | 欧美videos娇小 | 亚洲精品一区二区三区www | 欧美激情性色生活片在线观看 | 日韩在线一区二区三区视频 | 亚洲爱视频 | www.久草.com | 久久久久久国产精品免费免费 | 自拍三级视频 | 一级爱做片免费观看久久 | 国产精品国产自线在线观看 | 爽爽爽爽爽爽a成人免费视频 | 免费看欧美一级特黄a毛片 免费看片aⅴ免费大片 | 性色aⅴ在线观看swag | 亚洲在线视频免费观看 | 偷拍自拍第一页 | 欧美日韩第三页 | 一级做性色a爰片久久毛片 一级做性色a爰片久久毛片免费 | 白白在线观看永久免费视频 | a级国产精品片在线观看 | 国产欧美在线观看 | 国产精品成aⅴ人片在线观看 | 日韩中文字幕一在线 | 欧美成人精品手机在线观看 | 99热精品在线观看 | 国产精品国产三级国产专区5o | 久久精品一区二区影院 | 国产大臿蕉香蕉大视频 | 美女又黄又免费视频 | 精品一区二区影院在线 | 国产精品高清免费网站 | 亚洲精品一区二区三区第四页 | 日韩一级在线视频 |