国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

Android實現兩個數相加功能

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

本文實例為大家分享了Android實現兩個數相加的具體代碼,供大家參考,具體內容如下

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

Android實現兩個數相加功能

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='請輸入整數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='請輸入整數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='確認'/> <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); } }); }}

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

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

標簽: Android
相關文章:
主站蜘蛛池模板: 91tv成人影院免费 | 亚洲 欧美 在线观看 | 国产欧美日韩在线观看精品 | 免费永久观看美女视频网站网址 | 成年人三级网站 | 久久毛片免费 | 精品久久久久久久高清 | 亚洲bbbbbxxxxx精品三十七 | 欧美三级视频在线观看 | 免费观看欧美一级牲片一 | 久久久久久久国产精品 | 亚洲免费专区 | 亚洲精品午夜久久久伊人 | 国产亚洲精品福利片 | 在线综合亚洲欧美自拍 | 亚洲在线观看免费 | 欧美亚洲一区二区三区 | 精品国产一区二区三区免费 | 亚洲九九视频 | 小屁孩cao大人免费网站 | 成人免费在线视频网 | 普通话对白国产情侣自啪 | 亚洲自偷自拍另类12p | 国产高中生粉嫩无套第一次 | 美女网站色免费 | 精品国产免费第一区二区 | 午夜在线亚洲男人午在线 | 国产人妖xxxx做受视频 | 看一级特黄a大一片 | 国产人成亚洲第一网站在线播放 | 亚洲二区在线观看 | 在线亚洲精品自拍 | 国产大陆亚洲精品国产 | 国产一级aaa全黄毛片 | 亚洲精品自拍视频 | 国产一级特黄aaa大片 | 精品视频h | 日本中文字幕不卡免费视频 | 精品一区二区三区五区六区 | 成在线人永久免费播放视频 | 蕾丝视频永久在线入口香蕉 |