位置: 编程技术 - 正文

android计算器(Android计算器项目代码)

编辑:rootadmin

推荐整理分享android计算器(Android计算器项目代码),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:Android计算器代码,Android计算器代码用输入框,Android计算器代码用输入框,android计算器实现实验总结,Android计算器布局,android计算器实现实验总结,Android计算器代码,Android计算器代码,内容如对您有帮助,希望把文章链接给更多的朋友!

主类:

package com.bn.es2b;//包名import android.app.Activity; import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.view.View.OnClickListener;public class Sample2_2_Activity extends Activity {TextView tv;int[] buttons;//数字按钮数组int result;int result0;int result1;Button buttonC;//按钮对象声明Button buttonJia;Button buttonJian;Button buttonCheng;Button buttonChu;Button buttonDengyu;String str1; //旧输入的&#;String str2; //新输入的&#;int flag=0; //计算标志位,0第一次输入;1加;2减;3乘;4除;5等于Button temp;@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //跳转到main界面 initButton(); //清空按钮的点击事件监听器 buttonC.setOnClickListener ( new OnClickListener() { public void onClick(View v) {str1="";str2=""; //清空记录tv.setText(str1);flag=0;}} ); //监听 for(int i=0;i<buttons.length;i&#;&#;) { temp=(Button)findViewById(buttons[i]); temp.setOnClickListener ( //为Button添加监听器 new OnClickListener() { public void onClick(View v) { //此处为计算器的关键代码

// 当第一次按下按钮时,str1="";之后再累加数字,之前一直没有弄懂的,现在知道了

android计算器(Android计算器项目代码)

str1=tv.getText().toString().trim(); str1=str1&#;String.valueOf(((Button)v).getText());//获得新输入的&#; 参数v此时是按钮,所以需要强制转换; System.out.println("str1"&#;":::"&#;str1); tv.setText(str1);} } ); } buttonListener(buttonJia,1); buttonListener(buttonJian,2); buttonListener(buttonCheng,3); buttonListener(buttonChu,4); buttonDengyu.setOnClickListener ( new OnClickListener() { public void onClick(View v) {System.out.println(str1); result1=Integer.parseInt(str1); if(flag==1) { result=result0&#;result1; System.out.println(result0&#;":"&#;result1); } else if(flag==2) { result=result0-result1; } else if(flag==3) { result=result0*result1; } else if(flag==4) { result=(int)(result0/result1); } String str=(result&#;"").trim(); System.out.println(str); tv.setText(str); } } ); }//初始化按钮 public void initButton() { //初始化控件资源 tv=(TextView)this.findViewById(R.id.tv);//获取文本框控件对象 str1=String.valueOf(tv.getText());str2=""; //初始化运算输入数&#; buttonC=(Button)this.findViewById(R.id.ButtonC);//获得计算按钮的按钮对象 buttonJia=(Button)this.findViewById(R.id.ButtonJia); buttonJian=(Button)this.findViewById(R.id.ButtonJian); buttonCheng=(Button)this.findViewById(R.id.ButtonCheng); buttonChu=(Button)this.findViewById(R.id.ButtonChu); buttonDengyu=(Button)this.findViewById(R.id.ButtonDengyu); buttons=new int[] { //记录数&#;按钮的id R.id.Button,R.id.Button,R.id.Button,R.id.Button,R.id.Button, R.id.Button,R.id.Button,R.id.Button,R.id.Button,R.id.Button }; } //按钮监听 public void buttonListener(Button button,final int id) { button.setOnClickListener ( new OnClickListener() { public void onClick(View v) { String str=tv.getText().toString().trim(); result0=Integer.parseInt(str); tv.setText(""); flag=id; } } ); }}

布局文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingTop="5dip"> <TextView android:id="@&#;id/tv" android:layout_width="fill_parent" android:layout_height="dip" android:layout_marginRight="5dip"android:layout_marginLeft="5dip" android:background="#FFFFFF" android:gravity="center_vertical|right" android:textSize="dip" android:textColor="#ff"> </TextView> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dip"> <Button android:text="7" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="8" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="9" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="&#;" android:textSize="dip" android:id="@&#;id/ButtonJia" android:layout_width="dip" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dip"> <Button android:text="4" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="5" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="6" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="-" android:textSize="dip" android:id="@&#;id/ButtonJian" android:layout_width="dip" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dip"> <Button android:text="1" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="2" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="3" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="*" android:textSize="dip" android:id="@&#;id/ButtonCheng" android:layout_width="dip" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dip"> <Button android:text="0" android:textSize="dip" android:id="@&#;id/Button" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="c" android:textSize="dip" android:id="@&#;id/ButtonC" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="=" android:textSize="dip" android:id="@&#;id/ButtonDengyu" android:layout_width="dip" android:layout_height="wrap_content"/> <Button android:text="/" android:textSize="dip" android:id="@&#;id/ButtonChu" android:layout_width="dip" android:layout_height="wrap_content"/> </LinearLayout></LinearLayout>

我是如何从0开始,在天里完成一款Android游戏开发的 – Part3 – 第6至第8天 第6天:第一批外星人和屏幕方向好了,现在有了一些复古风的外星人它们正在到处飞。抱歉,暂时还没有demo。这款Andriod游戏目前只有.apk式的安装包。

我是如何从0开始,在天里完成一款Android游戏开发的 – Part4 – 第9至第天 第9天这是一款第一人称视角射击游戏,但它绝不老套在与人们谈论起这款游戏的时候,为它定义一个明确的分类确实很难。虽然可以将它看作一款传统

我是如何从0开始,在天里完成一款Android游戏开发的 – Part5– 第至第天 第天(第一部分):新游戏名DRONEINVADER名字终于选好了。备选名字有很多,但只有6、7个是可用的。这一个看起来最符合游戏的主题。全新的主题也做

标签: Android计算器项目代码

本文链接地址:https://www.jiuchutong.com/biancheng/371194.html 转载请保留说明!

上一篇:我是如何从0开始,在23天里完成一款Android游戏开发的 – Part 2 – 第3至第5天(如何从0开始赚钱)

下一篇:我是如何从0开始,在23天里完成一款Android游戏开发的 – Part3 – 第6至第8天(从0开始)

  • 餐饮毛利率多少是赚钱的
  • 航空公司能开电动车吗
  • 预付账款需要纳税申报吗
  • 企业所得税不预缴年终汇算可以吗
  • 母公司出售子公司给另一家子公司
  • 房地产企业毛利率计算公式是什么
  • 建筑业企业纳税人税率是多少
  • 年初数和年末数审计报告不一致
  • 土地使用权出让金多少钱一平米
  • 符合条件的居民企业之间股息红利
  • 开具的红字发票金税三期怎么报税?
  • 工程承建方给予的工期奖励如何做账?
  • 工资代扣款项是什么意思
  • 销售生产用原材料取得的收入计入什么科目
  • 购买投资理财产品放的会计处理怎么做?
  • 案例分析改变,从三块板开始
  • 发票对方已认证怎么冲红
  • 债转股需不需要交税
  • 污水处理服务费用交印花税吗
  • 股东以资产入股公司
  • 待抵扣进项税 待认证进项税
  • 社保已申报未缴费可以减员吗
  • 税局代开专票季度未达起征点怎么缴纳地税?
  • 人力资源外包公司发展前景
  • 开发间接费用定义
  • 个人综合所得适用什么税率?
  • 在win7系统中将打开窗口拖到屏幕顶端
  • 埃托沙国家公园发展观兽旅游的优势条件
  • 采购周转材料会计分录怎么写
  • thinkphp上传文件
  • pytorch中的数据类型
  • php设置目录权限
  • java 日志系统
  • 中国石化电子发票平台官网
  • 存量资金上缴财政款 预算会计
  • 收回款项的会计处理分录
  • mongodb导入数据三种方式
  • 总分公司企业所得税如何申报缴纳
  • 企业所得税太高怎么合理规避
  • 报税是按照实际收入还是开票
  • 无偿受让股权是利好吗
  • 个人发票抬头和税号是什么
  • linux安装ms
  • 增值税留抵有时间限制吗
  • 明细分类账户的名称,核算内容及使用方法是什么规定的
  • 承兑汇票利息分录
  • 调整凭证能不能做2个贷方
  • 主营业务收入的计算公式
  • 不良品扣款会计分录
  • 销售货物退款会计分录
  • 购买库存商品的运输费
  • 没有计提社保如何处理
  • 签合同的名称和内容
  • 准予抵扣销项税额
  • 关于财务报销的法律
  • 报销单扣除金额什么意思
  • 医疗器械销售能一年挣一百万么
  • 农产品进项税额会计分录
  • 办公用品怎么开大额发票
  • 银行汇票如何兑现金
  • sql server怎么添加数据
  • win8.1开机密码忘了
  • 系统引导程序出错了如何修复
  • windows8怎么设置
  • win7系统ie8浏览器
  • win8.1怎么关机
  • 电脑自带的groove音乐用不了
  • jquery跟随鼠标移动
  • 安卓 unity
  • linux shell $1
  • 批处理打开网络连接
  • Jquery uploadify上传插件使用详解
  • css li横向显示
  • python 解析算法
  • python mor
  • 增值税开票系统如何添加开票人
  • 供电局发票是什么样子的
  • 货物无偿赠予政府怎么写
  • 东莞房地产协会副会长
  • 扬州税务学院住宿环境
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设