基于Android计算器功能的实现

合集下载

基于Android的雷达遮蔽角计算器设计

基于Android的雷达遮蔽角计算器设计

件 界 面和 遮 蔽角计 算 功 能的 实现 方 法。 实验 结 果表 明,软 件 安装 简单 , 易于使 用 ,大 大提 高 了遮 蔽角计 算 效 率,缩 短 了雷达 部 队 战斗 准备 时 间,对 提 升部 队打 赢 能力具有 现实意义。
2 . 1 软 件 界 面设 计
良好 的人机 交 互界 面 能够 提升 用户 的操 作体验 ,便于软件普及和 推广。为突 出软件 实 用性和 易用性 ,人机 界面 力求简洁 明了。通 过 前面 分析,计算遮蔽 角的参数主要有 3个 ,可
件 , 以提 高遮 蔽 角 计 算 效 率 。
2 . 2按钮点击 事件
软 件 的 主 要 功 能 是 实 现 公 式 的 求 解 计 算 , 通 过 点 击 Bu t o n控 件 开 始 执 行 主 程 序 , 即 响 应 按 钮 点 击 事 件 。在 r e s / l a y o u t / a c t i v i t y
其实 就是 一个形 如 x x x ( Vi e w s o u r c e 1的方法 的 方法名 ,这 样直接就在界面布 局文件 中为指定 控件绑 定了事件处理方法 。同时在该界面布局
对 应 的 Ma i n Ac t i v i t y . j a v a文 件 中 定 义 一 个 v o i d c l i c k Ha n l e r ( Vi e w s o u r c e ) 方 法 , 该 方 法 将 会 处 理 该 按 钮 上 的 点 击 事 件 。关 键 代 码 如 下 :
遮 蔽角 作 为雷 达阵 地地 形 条件 技术 指标
重 要 内容 之 一 , 是 测 算 雷 达 探 测 盲 区 的 基 础 。
局 把 全 部 控 件 按 照 行 、 列 方 式 排 列 , 以 完 成 整 体布局 。

Android框架上的简单计算器界面设计

Android框架上的简单计算器界面设计

为了深入理解和应用Android框架系统的控件以及更加熟练的掌握eclips的开发技巧,所以就决定做一个简单的计算器来了解和介绍一下Android界面设计的基本技巧。

界面的样子如下:这个界面由一个编辑框和很多按钮组成。

他的功能跟Windows下的计算其功能差不多,就是实现+-*/等功能。

这个还实现了一个菜单的功能。

按一下Exit就可以离开这个应用程序了。

Android框架定义了很多布局(Layout)架构。

布局就像容器,里面可以装下很多控件。

布局里面还可以套用其他的布局。

这样就可以实现界面的多样化以及设计的灵活性。

在这个界面中,我们应用了一个LinearLayout的布局,它是垂直向下扩展的。

在这个LinearLayout中,我们可以应用一个EditText和一个TableLayout 作为他的子控件。

在TableLayout布局可以实现以表格的形式来布局空间。

而TableRow是用来定义每一行。

在TableLayout中,列的宽度是取其中这一列中宽度最大的控件的宽度。

这个应用程序正好用到5x5的一个表格,TableLayout将是最好的选择了。

Android界面编程的一个优势是他的布局全部可以用xml文件来描述,实现了即改即现的方式。

ADT又在Eclips里面做了一个Outline的插件。

当你打开布局xml文件的时候,Outline就会显示布局的所有控件以及他们的结构。

双击其中的控件就会打开空间的属性。

你就可以直接编辑属性来轻松实现界面的布局。

所改的属性也将立刻在xml文件中显示出来。

以下是描述这个简单计算器的界面xml文件给大家做个参考:android:background="#ff808080"><EditText android:id="@+id/input"android:layout_width="fill_parent"android:layout_height="wrap_content"android:cursorVisible="false"android:gravity="right"android:editable ="false"/><TableLayout xmlns:android="/apk/res/android" android:layout_width="fill_parent"android:layout_height="fill_parent"><TableRowandroid:layout_width="fill_parent"android:layout_height="wrap_content"><Button android:id="@+id/seven"android:text="7"android:layout_height="wrap_content"android:layout_width="63sp"/><Button android:id="@+id/eight"android:text="8"android:layout_width="63sp"android:layout_height="wrap_content" /><Button android:id="@+id/nine"android:text="9"android:layout_width="63sp"android:layout_height="wrap_content" /><Button android:id="@+id/divide"android:text="/"android:layout_width="63sp"android:layout_height="wrap_content" /><Button android:id="@+id/sqrt"android:text="sqrt"android:layout_width="63sp"android:layout_height="wrap_content" /></TableRow><TableRowandroid:layout_width="fill_parent"android:layout_height="wrap_content"><Button android:id="@+id/four"android:text="4"android:layout_width="63sp"android:layout_height="wrap_content" /><Button android:id="@+id/five"android:text="5"<Button android:id="@+id/multiply"android:text="*"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/remainder"android:text="%"android:layout_width="63sp"android:layout_height="wrap_content" /></TableRow><TableRowandroid:layout_width="fill_parent"android:layout_height="wrap_content"><Button android:id="@+id/one"android:text="1"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/two"android:text="2"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/three"android:text="3"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/minus"android:text="-"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/convert"android:text="1/x"android:layout_width="63sp"android:layout_height="wrap_content" /> </TableRow><TableRowandroid:layout_width="fill_parent"android:layout_height="wrap_content"><Button android:id="@+id/zero"android:text="0"android:layout_width="63sp"android:layout_height="wrap_content" /> <Button android:id="@+id/digit"android:text="."。

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现

基于安卓的计算器的设计与实现在设计和实现基于安卓的计算器时,需要考虑以下几个重要的方面:用户界面设计、计算逻辑实现和功能扩展。

首先,用户界面设计是一个计算器的重要组成部分。

一个简洁直观、易于使用的界面可以提供良好的用户体验。

可以考虑使用标准计算器的布局,包括数字键盘、运算符按钮和显示结果的文本框。

此外,还可以添加一些额外的功能,比如一键清除按钮、括号按钮和科学计算模式切换按钮等。

考虑到不同屏幕尺寸和定制化需求,应该使用相对布局或者网格布局来放置UI元素。

其次,计算逻辑实现是计算器的核心部分。

需要支持基本的四则运算,包括加法、减法、乘法和除法。

为了实现连续运算和操作优先级,可以使用栈或者逆波兰表示法。

在用户输入数字和运算符时,应该及时更新显示结果的文本框。

另外,还应该考虑异常情况的处理,比如除数为零的情况。

最后,功能扩展是一个好的设计的关键。

除了基本的四则运算,还可以考虑添加一些其他功能,比如开方、求平方、取余、倒数、阶乘等。

另外,还可以添加一个历史记录功能,记录用户的计算过程和结果,方便用户查看和回顾。

此外,还可以添加一个单位转换功能,支持常见的长度、重量、温度、时间、速度等单位之间的转换。

在实际开发中,可以使用Android Studio作为开发工具。

Android Studio提供了丰富的界面设计工具和模拟器,可以方便地进行界面布局和调试。

可以使用Java语言进行开发,使用Android提供的API来处理用户输入和展示结果。

在代码实现中,可以使用按钮点击事件来处理用户输入。

当用户点击数字按钮时,将所点击的数字添加到一个临时变量中,当用户点击运算符按钮时,将临时变量中的数字和运算符添加到运算式中,并清空临时变量。

当用户点击等号按钮时,根据运算式中的数字和运算符进行实际的计算,并将结果显示在结果文本框中。

当用户点击清空按钮时,将运算式和结果文本框清空。

除了基本逻辑实现外,还可以进行一些优化和改进。

在Android Studio中开发一个简单的计算器应用

在Android Studio中开发一个简单的计算器应用

在Android Studio中开发一个简单的计算器应用随着智能手机的普及,计算器应用成为了人们生活中不可或缺的工具之一。

为了满足用户的需求,我们决定在Android Studio中开发一个简单的计算器应用。

这个应用将提供基本的四则运算功能,并且界面简洁易用。

首先,在Android Studio中创建一个新的项目。

选择合适的应用名称和包名。

接下来,我们需要设计应用的用户界面。

我们希望用户界面简洁明了,方便用户使用。

可以考虑使用一个TextView显示计算结果,以及多个Button用于输入数字和操作符。

在开发计算器的过程中,我们需要处理用户的输入并进行相应的计算。

为此,我们可以使用一个EditText控件来接收用户的输入,并通过按钮的点击事件来获取用户点击的数字和操作符。

然后,我们可以使用Java中的数学库来进行四则运算,并将结果显示在TextView中。

通过Android Studio提供的布局编辑器,我们可以轻松地将TextView和Button布局在界面上。

可以使用LinearLayout或RelativeLayout进行布局,根据需要设置各个控件之间的位置和大小。

此外,还可以设置按钮的点击事件,使其能够响应用户的输入。

在处理用户输入时,需要考虑一些特殊情况。

例如,当用户输入非法字符或进行除法时需要进行错误处理。

可以通过在代码中添加条件判断语句来实现这些功能。

另外,还可以添加一些额外的功能,如清除输入、撤销操作等,以提升用户体验。

在开发过程中,可以使用Android Studio提供的调试工具来检查代码是否正常运行。

可以设置断点,逐步执行代码,并查看变量的值。

这些工具能够帮助我们快速定位和修复错误。

为了使应用具有良好的用户体验,我们还可以添加一些动画效果和过渡效果。

例如,当用户点击按钮时,可以添加按钮缩放、淡入淡出等动画效果,使界面更加生动有趣。

除了基本功能以外,我们还可以考虑添加更多的功能来完善应用。

Android入门程序开发—BMI计算器

Android入门程序开发—BMI计算器

Android入门程序开发—BMI计算器作者:董明华李宏伟来源:《电脑知识与技术》2017年第35期摘要:AndroidStudio已经代替了Eclipse,成为Android官方集成开发工具。

文章基于AndroidStudio设计了一款身高体重计算器,通过介绍常见布局控件的用法,使初学者能够快速入门Android APP开发,了解APP界面设计,用户输入值的获取等知识。

关键词:AndroidStudio;BMI;APP中图分类号:TP311 文献标识码:A 文章编号:1009-3044(2017)35-0136-031 背景BMI指数,即身体质量指数,是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。

体质指数(BMI)=体重(kg)÷身高^2(m)。

文章根据BMI指数开发一款简易身高体重计算器,通过分析用户的身高体重值,判断其身材是否标准。

2 APP展示最终APP效果如图1所示,用户输入身高体重值后,通过单击计算按钮,可得出身体胖瘦程度的一个提示。

3 知识点分析项目涉及知识点较为简单,界面布局为LinearLayout,控件为EditText和Button,java源代码部分主要是控件的初始化,取得文本输入框的输入值,并转换为数值类型,然后计算出BMI指数值,并通过Toast给出提示。

4 界面设计界面从上向下依次为身高输入框、体重输入框和按钮,输入框对应Android中的EditText 控件,按钮对应Button控件,垂直排列的布局适合用线性布局LinearLayout。

布局主要作用是设置控件在屏幕上的位置,线性布局LinearLayout可以让其中的控件水平排列或者垂直排列。

首先,在res/layout文件夹中找到自动生成的布局文件activity_main.xml。

在此文件中声明父布局LinearLayout的排版方向为垂直排列,通过设置android:orientation的属性值为vertical 实现。

android开发计算器课程设计

android开发计算器课程设计

android开发计算器课程设计一、教学目标本课程旨在通过学习Android开发计算器,使学生掌握Android应用开发的基本知识和技能,能够独立设计和开发简单的Android计算器应用。

1.理解Android开发的基本概念和框架。

2.掌握Android计算器的界面设计和事件处理。

3.熟悉Android计算器的数据存储和运算逻辑。

4.能够使用Android Studio进行基本的Android应用开发。

5.能够设计并实现一个简单的Android计算器应用。

6.能够对Android计算器应用进行调试和优化。

情感态度价值观目标:1.培养学生的创新意识和问题解决能力。

2.培养学生对Android开发技术的兴趣和热情。

3.培养学生的团队合作精神和自主学习能力。

二、教学内容本课程的教学内容主要包括Android开发的基本概念和框架、Android计算器的界面设计和事件处理、Android计算器的数据存储和运算逻辑等。

1.Android开发的基本概念和框架:介绍Android Studio的使用、Android应用的结构和生命周期、Activity和Service的概念和用法。

2.Android计算器的界面设计:介绍布局文件的使用、控件的属性和事件处理。

3.Android计算器的数据存储和运算逻辑:介绍SharedPreferences和SQLite数据库的使用、运算器的实现和数据的存储。

三、教学方法本课程将采用讲授法、案例分析法和实验法等多种教学方法相结合的方式进行教学。

1.讲授法:通过讲解和演示,使学生理解Android开发的基本概念和框架、Android计算器的界面设计和事件处理、Android计算器的数据存储和运算逻辑。

2.案例分析法:通过分析典型的Android计算器应用案例,使学生掌握Android计算器的界面设计和事件处理、数据存储和运算逻辑的实现。

3.实验法:通过实际操作和调试,使学生掌握Android计算器的界面设计和事件处理、数据存储和运算逻辑的实现。

基于Android计算器功能的实现

基于Android计算器功能的实现

基于Android计算器功能的实现摘要随着移动通信技术和网络技术的迅速发展,手机系统发生了巨大的变化,从进行简单通话功能的非智能手机到现在集上网、聊天、收发邮件、视屏电话会议等各种服务于娱乐为一身的智能手机系统。

由Google公司牵头众多实力雄厚的软硬件厂商加盟成立了OMS联盟,并推出的Android平台手机系统。

作为时代的新生儿,Android手机操作平台有着得天独厚的优势广阔的发展前景。

本文正是基于Android平台开发的计算器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 设计并实现基于Android的计算器。

论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,其次对计算器系统和程序进行了分析和设计,再次对计算器进行了系统的实现,并对系统进行了严格的验证,最后本文对所做工作进行了总结。

关键词:手机,Android,用户界面,计算器THE CALCULATOR FUNCTION REALIZATION BASEDON ANDROIDABSTRACTWith the development of mobile communication technology and network technology, great changes have taken place on the mobile phone system. The original mobile phone only has the functions of communication and Smartphone has the functions of internet, chat, video conferencing and other services and entertainment. Android mobile phone platform which was developed by Google Company and many equipment manufacturers of hardware and software vendors, as the era of neonatal has a unique advantage and prospects for development. This article is based on the Android platform calculator. The thesis describes object-oriented programming language eclipse development tools, design and implement a calculator based on the Android. The paper first introduces the Android development platform and environment as well as an important part of the Android project, followed by the calculator systems and procedures analysis and design, the realization of the system once again the calculator, and strict verification, Finally, a summary of the work done.Key words: mobile phone, Android, UI, calculator目录1 引言 (1)1.1 课题背景及意义 (1)1.1.1 课题背景 (1)1.1.2 课题意义 (1)1.2 智能手机平台系统 (2)1.3 课题来源 (3)2 基于Android平台计算器相关技术概述 (4)2.1 Android手机平台 (5)2.1.1 Android起源及优势 (5)2.1.2 Android体系结构 (5)2.1.3 Android平台功能特征 (7)2.2 Android SDK介绍 (9)2.3 XML技术 (10)2.4 JNI技术 (11)3 基于Android平台计算器设计 (12)3.1 系统的总体设计 (12)3.2 程序流程和系统功能设计 (13)3.2.1 程序流程设计 (13)3.2.2 系统功能设计 (14)3.3基于Android平台系统具体设计 (15)3.3.1 总体模块详细设计 (15)3.3.2 输入模块详细设计 (16)3.3.3 显示模块详细设计 (16)3.3.4 计算模块详细设计 (17)4 计算器系统实现 (18)4.1 Android应用程序构成 (18)4.2 Android应用系统文件结构 (19)4.3 构建Android应用程序用户界面 (21)4.3.1 Android应用程序界面组件 (21)4.3.2 Android应用系统界面组件 (22)4.3.3 Android用户界面的实现 (24)4.4 计算模块的实现 (28)4.5 计算器演示 (30)5 结论 (32)谢辞 (33)参考文献 (34)附录1: (36)附录2: (38)1 引言1.1 课题背景及意义1.1.1 课题背景随着社会的发展,经济水平的提高,手机越来越普及。

制作一个简易计算器——基于AndroidStudio实现

制作一个简易计算器——基于AndroidStudio实现

制作⼀个简易计算器——基于AndroidStudio实现⼀个计算器Android程序的源码部分分为主⼲和细节两部分。

⼀、主⼲1. 主⼲的构成计算器的布局事件(即计算器上的按钮、⽂本框)监听实现计算2. 详细解释 假设我们的项⽬名为Calculator,⽽布局名称(Layout Name)为默认的activity_main 。

即设置如下图所⽰: 在这种前提下,有:设置计算器布局的⽂件:Calculator/app/src/main/res/layout/activity_main.xml事件监听和计算实现在同⼀个⽂件⾥:Calculator/app/src/main/java/下的⼀个⼦⽬录⾥的MainActivity.java 即如下图所⽰:计算器布局代码(写在activity_main.xml⽂件⾥):1<?xml version="1.0" encoding="utf-8"?>2<ScrollView xmlns:android="/apk/res/android"3 android:layout_width="fill_parent"4 android:layout_height="wrap_content"5>6<LinearLayout7android:layout_width="fill_parent"8 android:layout_height="fill_parent"9 android:orientation="vertical">10<EditText11android:id="@+id/input"12 android:layout_width="fill_parent"13 android:layout_height="wrap_content"14 android:layout_gravity="center"15 android:editable="false"16 android:hint="@string/shuru"/>1718<EditText19android:id="@+id/output"20 android:layout_width="fill_parent"21 android:layout_height="wrap_content"22 android:layout_gravity="center"23 android:editable="true"24 android:gravity="right"25 android:hint="@string/shuchu"/>2627<RelativeLayout28android:layout_width="fill_parent"29 android:layout_height="wrap_content">3031<Button32android:id="@+id/seven"33 android:layout_width="80dp"34 android:layout_height="70dp"35 android:layout_alignParentLeft="true"36 android:text="@string/seven"37 android:textSize="40sp"/>3839<Button44 android:text="@string/eight"45 android:textSize="40sp"/>4647<Button48android:id="@+id/nine"49 android:layout_width="80dp"50 android:layout_height="70dp"51 android:layout_toRightOf="@id/eight"52 android:text="@string/nine"53 android:textSize="40sp"/>5455<Button56android:id="@+id/add"57 android:layout_width="80dp"58 android:layout_height="70dp"59 android:layout_alignParentRight="true"60 android:layout_toRightOf="@id/nine"61 android:text="@string/add"62 android:textSize="40sp"/>6364<Button65android:id="@+id/four"66 android:layout_width="80dp"67 android:layout_height="70dp"68 android:layout_alignParentLeft="true"69 android:layout_below="@id/seven"70 android:text="@string/four"71 android:textSize="40sp"/>7273<Button74android:id="@+id/five"75 android:layout_width="80dp"76 android:layout_height="70dp"77 android:layout_below="@id/eight"78 android:layout_toRightOf="@id/four"79 android:text="@string/five"80 android:textSize="40sp"/>8182<Button83android:id="@+id/six"84 android:layout_width="80dp"85 android:layout_height="70dp"86 android:layout_below="@id/nine"87 android:layout_toRightOf="@id/five"88 android:text="@string/six"89 android:textSize="40sp"/>9091<Button92android:id="@+id/subtract"93 android:layout_width="80dp"94 android:layout_height="70dp"95 android:layout_alignParentRight="true"96 android:layout_below="@id/add"97 android:layout_toRightOf="@id/six"98 android:text="@string/subtract"99 android:textSize="40sp"/>100101<Button102android:id="@+id/one"103 android:layout_width="80dp"104 android:layout_height="70dp"105 android:layout_alignParentLeft="true" 106 android:layout_below="@id/four"107 android:text="@string/one"108 android:textSize="40sp"/>109110<Button111android:id="@+id/two"112 android:layout_width="80dp"113 android:layout_height="70dp"114 android:layout_below="@id/five"115 android:layout_toRightOf="@id/one" 116 android:text="@string/two"117 android:textSize="40sp"/>118119<Button120android:id="@+id/three"121 android:layout_width="80dp"122 android:layout_height="70dp"123 android:layout_below="@id/six"128<Button129android:id="@+id/multiply"130 android:layout_width="80dp"131 android:layout_height="70dp"132 android:layout_alignParentRight="true" 133 android:layout_below="@id/subtract" 134 android:layout_toRightOf="@id/three" 135 android:text="@string/multiply"136 android:textSize="40sp"/>137138<Button139android:id="@+id/zero"140 android:layout_width="80dp"141 android:layout_height="70dp"142 android:layout_alignParentLeft="true" 143 android:layout_below="@id/one"144 android:text="@string/zero"145 android:textSize="40sp"/>146147<Button148android:id="@+id/clear"149 android:layout_width="80dp"150 android:layout_height="70dp"151 android:layout_below="@id/two"152 android:layout_toRightOf="@id/zero" 153 android:text="@string/clear"154 android:textSize="40sp"/>155156<Button157android:id="@+id/result"158 android:layout_width="80dp"159 android:layout_height="70dp"160 android:layout_below="@id/three"161 android:layout_toRightOf="@id/clear" 162 android:text="@string/result"163 android:textSize="40sp"/>164165<Button166android:id="@+id/divide"167 android:layout_width="80dp"168 android:layout_height="70dp"169 android:layout_alignParentRight="true" 170 android:layout_below="@id/multiply" 171 android:layout_toRightOf="@id/result" 172 android:text="@string/divide"173 android:textSize="40sp"/>174175<Button176android:id="@+id/dot"177 android:layout_width="80dp"178 android:layout_height="70dp"179 android:layout_alignParentLeft="true" 180 android:layout_below="@id/zero"181 android:text="@string/dot"182 android:textSize="40sp"/>183<Button184android:id="@+id/writeButton"185 android:layout_width="wrap_content" 186 android:layout_height="wrap_content" 187 android:layout_alignParentLeft="true" 188 android:layout_below="@id/dot"189 android:text="@string/write"190 android:textSize="40sp"/>191<Button192android:id="@+id/readButton"193 android:layout_width="wrap_content" 194 android:layout_height="wrap_content" 195 android:layout_alignParentRight="true" 196 android:layout_below="@id/dot"197 android:text="@string/read"198 android:textSize="40sp"/>199200<CheckBox201android:id="@+id/appendBox"202 android:text="@string/appendBox"203 android:layout_width="wrap_content" 204 android:layout_height="wrap_content" 205 android:layout_alignParentBottom="true" 206 android:layout_toLeftOf="@+id/divide" 207 android:layout_toStartOf="@+id/divide"212213<EditText214215android:layout_width="match_parent"216 android:layout_height="wrap_content"217 android:id="@+id/textView"/>218219<EditText220221android:layout_width="match_parent"222 android:layout_height="wrap_content"223 android:id="@+id/displayView"/>224225<EditText226android:id="@+id/errorzero"227 android:layout_width="fill_parent"228 android:layout_height="wrap_content"229 android:layout_gravity="center"230 android:editable="false"231 android:gravity="center"232/>233<EditText234android:id="@+id/resultText"235 android:layout_width="fill_parent"236 android:layout_height="wrap_content"237 android:layout_gravity="center"238 android:editable="false"239 android:gravity="left"240 android:text="@string/resultText"241/>242</LinearLayout>243</ScrollView>View Code事件监听和实现计算代码(写在MainActivity.java⽂件⾥)1package com.example.lenovo.calculator;2345import android.app.Activity;6import android.content.Context;7import android.os.Bundle;8import android.view.View;9import android.view.View.OnClickListener;10import android.widget.Button;11import android.widget.CheckBox;12import android.widget.EditText;1314import java.io.FileInputStream;15import java.io.FileNotFoundException;16import java.io.FileOutputStream;17import java.io.IOException;1819public class MainActivity extends Activity {20/**21 * Called when the activity is first created.22*/23private EditText output = null;24private EditText input = null;25private Button btn0 = null;26private Button btn1 = null;27private Button btn2 = null;28private Button btn3 = null;29private Button btn4 = null;30private Button btn5 = null;31private Button btn6 = null;32private Button btn7 = null;33private Button btn8 = null;34private Button btn9 = null;35private Button btnadd = null;36private Button btnsubtract = null;37private Button btnmultiply = null;38private Button btndivide = null;39private Button btnclear = null;40private Button btnresult = null;41private Button btndot = null;46private Button writeButton = null;47private Button readButton = null;48private CheckBox appendBox = null;49private EditText textView = null;50private EditText displayView = null;51public String FILE_NAME = "fileDemo.txt";525354private String str = "";//保存数字55private String strold = "";//原数字56private char act = ' ';//记录“加减乘除等于”符号57private int count = 0;//判断要计算的次数,如果超过⼀个符号,先算出来⼀部分58private Float result = null;//计算的输出结果59private Boolean errBoolean = false;//有错误的时候为true,⽆错为false60private Boolean flagBoolean = false;//⼀个标志,如果为true,可以响应运算消息,如果为false,不响应运算消息,只有前⾯是数字才可以响应运算消息 61private Boolean flagDot = false; //⼩数点标志位62636465 @Override66public void onCreate(Bundle savedInstanceState) {67super.onCreate(savedInstanceState);68 setContentView(yout.activity_main);6970 output = (EditText) findViewById(R.id.output);71 input = (EditText) findViewById(R.id.input);7273 errorzero = (EditText) findViewById(R.id.errorzero);74 resultText = (EditText) findViewById(R.id.resultText);75 writeButton = (Button) findViewById(R.id.writeButton);76 readButton = (Button) findViewById(R.id.readButton);77 textView = (EditText) findViewById(R.id.textView);78 displayView = (EditText) findViewById(R.id.displayView);79 appendBox = (CheckBox) findViewById(R.id.appendBox);8081 btn0 = (Button) findViewById(R.id.zero);82 btn1 = (Button) findViewById(R.id.one);83 btn2 = (Button) findViewById(R.id.two);84 btn3 = (Button) findViewById(R.id.three);85 btn4 = (Button) findViewById(R.id.four);86 btn5 = (Button) findViewById(R.id.five);87 btn6 = (Button) findViewById(R.id.six);88 btn7 = (Button) findViewById(R.id.seven);89 btn8 = (Button) findViewById(R.id.eight);90 btn9 = (Button) findViewById(R.id.nine);91 btnadd = (Button) findViewById(R.id.add);92 btnsubtract = (Button) findViewById(R.id.subtract);93 btnmultiply = (Button) findViewById(R.id.multiply);94 btndivide = (Button) findViewById(R.id.divide);95 btnclear = (Button) findViewById(R.id.clear);96 btnresult = (Button) findViewById(R.id.result);97 btndot = (Button) findViewById(R.id.dot);98//设置按钮侦听事件99 btn0.setOnClickListener(listener);100 btn1.setOnClickListener(listener);101 btn2.setOnClickListener(listener);102 btn3.setOnClickListener(listener);103 btn4.setOnClickListener(listener);104 btn5.setOnClickListener(listener);105 btn6.setOnClickListener(listener);106 btn7.setOnClickListener(listener);107 btn8.setOnClickListener(listener);108 btn9.setOnClickListener(listener);109//执⾏运算110 btnadd.setOnClickListener(listener);111 btnsubtract.setOnClickListener(listener);112 btnmultiply.setOnClickListener(listener);113 btndivide.setOnClickListener(listener);114 btnclear.setOnClickListener(listener);115 btnresult.setOnClickListener(listener);116117 btndot.setOnClickListener(listener);118119 writeButton.setOnClickListener(writelistener);120 readButton.setOnClickListener(readlistener);121122123// ATTENTION: This was auto-generated to implement the App Indexing API.124// See https://g.co/AppIndexing/AndroidStudio for more information.125 }130public void onClick(View v) {131// TODO Auto-generated method stub132switch (v.getId()) {133//输⼊数字134case R.id.zero:135 num(0);136break;137case R.id.one:138 num(1);139break;140case R.id.two:141 num(2);142break;143case R.id.three:144 num(3);145break;146case R.id.four:147 num(4);148break;149case R.id.five:150 num(5);151break;152case R.id.six:153 num(6);154break;155case R.id.seven:156 num(7);157break;158case R.id.eight:159 num(8);160break;161case R.id.nine:162 num(9);163break;164165case R.id.dot:166 dot();167break;168//执⾏运算169case R.id.add:170 add();171break;172case R.id.subtract:173 sub();174break;175case R.id.multiply:176 multiply();177break;178case R.id.divide:179 divide();180break;181case R.id.clear:182 clear();183break;184//计算结果185case R.id.result:186 result();187if (!errBoolean && flagBoolean) {188 output.setText(String.valueOf(result));189 }190 resultText.setText(strold + act + str + "=" + result+" "); 191break;192193default:194break;195196 }197 input.setText(strold + act + str);198 output.setText(String.valueOf(result));199200201 }202 };203204private OnClickListener writelistener = new OnClickListener() {205 @Override206public void onClick(View view) {207//textView.setText("");208209 FileOutputStream fos = null;214 fos = openFileOutput(FILE_NAME, Context.MODE_PRIVATE); 215 }216 String text = resultText.getText().toString();217 fos.write(text.getBytes());218 textView.setText("⽂件写⼊成功,写⼊长度:" + text.length()); 219//resultText.setText("");220221 } catch (FileNotFoundException e) {222 e.printStackTrace();223 } catch (IOException e) {224 e.printStackTrace();225 }226finally {227if (fos != null)228try {229 fos.flush();230 fos.close();231 } catch (IOException e) {232 e.printStackTrace();233 }234 }235 }236 };237private OnClickListener readlistener = new OnClickListener() {238 @Override239public void onClick(View view) {240241 displayView.setText("");242 FileInputStream fis = null;243try {244 fis = openFileInput(FILE_NAME);245if (fis.available() == 0) {246return;247 }248byte[] readBytes = new byte[fis.available()];249while (fis.read(readBytes) != -1) {250251 }252 String text = new String(readBytes);253 displayView.setText(text);254 textView.setText("⽂件读取成功,写⼊长度:" + text.length()); 255256 } catch (FileNotFoundException e) {257 e.printStackTrace();258 } catch (IOException e) {259 e.printStackTrace();260 }261262 }263 };264265private void dot() {266// TODO Auto-generated method stub267268if (!flagDot) {269 str = str + ".";270 flagBoolean = false;271 flagDot = true;272 }273 }274275private void clear() {276// TODO Auto-generated method stub277 str = strold = "";278 count = 0;279 act = ' ';280 result = null;281 flagBoolean = false;282 flagDot = false;283 input.setText(strold + act + str);284 output.setText("");285 errorzero.setText("");286 displayView.setText("");287 textView.setText("");288 resultText.setText("");289 }290291private void divide() {292// TODO Auto-generated method stub293if (flagBoolean) {299300private void multiply() {301// TODO Auto-generated method stub 302if (flagBoolean) {303 check();304 act = '*';305 flagBoolean = false;306 }307 }308309private void sub() {310// TODO Auto-generated method stub 311if (flagBoolean) {312 check();313 act = '-';314 flagBoolean = false;315 }316 }317318private void add() {319// TODO Auto-generated method stub 320if (flagBoolean) {321 check();322 act = '+';323 flagBoolean = false;324 }325 }326327private void check() {328// TODO Auto-generated method stub 329if (count >= 1) {330 result();331 str = String.valueOf(result);332 }333 strold = str;334 str = "";335 count++;336 flagDot = false;337 errorzero.setText("");338 }339340//计算输出结果341private void result() {342// TODO Auto-generated method stub 343if (flagBoolean) {344 Float a, b;345346 a = Float.parseFloat(strold);347 b = Float.parseFloat(str);348349if (b == 0 && act == '/') {350 clear();351 errorzero.setText("除数不能为零!"); 352//output.setText("除数不能为零!"); 353354355//errBoolean=true;356 }357358359if (!errBoolean) {360switch (act) {361case '+':362 result = a + b;363break;364case '-':365 result = a - b;366break;367case '*':368 result = a * b;369break;370case '/':371 result = a / b;372break;373374default:375break;376 }377 }383private void num(int i) {384// TODO Auto-generated method stub385 str = str + String.valueOf(i);386 flagBoolean = true;387 errorzero.setText("");388 }389390 }View Code⼆、细节 仅仅将主⼲部分代码copy下来并不能运⾏程序,因为主⼲代码调⽤了⼀些⽂件的代码,这些⽂件就是我们所说的细节。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于Android计算器功能的实现摘要随着移动通信技术和网络技术的迅速发展,手机系统发生了巨大的变化,从进行简单通话功能的非智能手机到现在集上网、聊天、收发邮件、视屏电话会议等各种服务于娱乐为一身的智能手机系统。

由Google公司牵头众多实力雄厚的软硬件厂商加盟成立了OMS联盟,并推出的Android平台手机系统。

作为时代的新生儿,Android手机操作平台有着得天独厚的优势广阔的发展前景。

本文正是基于Android平台开发的计算器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 设计并实现基于Android的计算器。

论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,其次对计算器系统和程序进行了分析和设计,再次对计算器进行了系统的实现,并对系统进行了严格的验证,最后本文对所做工作进行了总结。

关键词:手机,Android,用户界面,计算器THE CALCULATOR FUNCTION REALIZATION BASEDON ANDROIDABSTRACTWith the development of mobile communication technology and network technology, great changes have taken place on the mobile phone system. The original mobile phone only has the functions of communication and Smartphone has the functions of internet, chat, video conferencing and other services and entertainment. Android mobile phone platform which was developed by Google Company and many equipment manufacturers of hardware and software vendors, as the era of neonatal has a unique advantage and prospects for development. This article is based on the Android platform calculator. The thesis describes object-oriented programming language eclipse development tools, design and implement a calculator based on the Android. The paper first introduces the Android development platform and environment as well as an important part of the Android project, followed by the calculator systems and procedures analysis and design, the realization of the system once again the calculator, and strict verification, Finally, a summary of the work done.Key words: mobile phone, Android, UI, calculator目录1 引言 (1)1.1 课题背景及意义 (1)1.1.1 课题背景 (1)1.1.2 课题意义 (1)1.2 智能手机平台系统 (2)1.3 课题来源 (3)2 基于Android平台计算器相关技术概述 (4)2.1 Android手机平台 (5)2.1.1 Android起源及优势 (5)2.1.2 Android体系结构 (5)2.1.3 Android平台功能特征 (7)2.2 Android SDK介绍 (9)2.3 XML技术 (10)2.4 JNI技术 (11)3 基于Android平台计算器设计 (12)3.1 系统的总体设计 (12)3.2 程序流程和系统功能设计 (13)3.2.1 程序流程设计 (13)3.2.2 系统功能设计 (14)3.3基于Android平台系统具体设计 (15)3.3.1 总体模块详细设计 (15)3.3.2 输入模块详细设计 (16)3.3.3 显示模块详细设计 (16)3.3.4 计算模块详细设计 (17)4 计算器系统实现 (18)4.1 Android应用程序构成 (18)4.2 Android应用系统文件结构 (19)4.3 构建Android应用程序用户界面 (21)4.3.1 Android应用程序界面组件 (21)4.3.2 Android应用系统界面组件 (22)4.3.3 Android用户界面的实现 (24)4.4 计算模块的实现 (28)4.5 计算器演示 (30)5 结论 (32)谢辞 (33)参考文献 (34)附录1: (36)附录2: (38)1 引言1.1 课题背景及意义1.1.1 课题背景随着社会的发展,经济水平的提高,手机越来越普及。

截止到2010年,中国手机用户数量将从2007年的5.40亿增长到7.38亿[1]。

同时伴随着移动互联网技术的发展,手机的功能也变得越来越丰富。

从原来只具有简单通信功能的非智能手机到现在具有手机操作系统,除通话功能以外,还集上网、聊天、炒股、收发邮件等功能于一身的智能手机系统。

智能手机[2]具有独立的操作系统,像个人电脑一样支持用户自行安装软件、游戏等第三方服务商提供的程序,并通过此类程序不断对手机的功能进行扩充,同时可通过移动通讯网络来实现无线网络接入。

智能手机同传统手机外观和操作方式类似,不仅包含触摸屏也包含非触摸屏、数字键盘手机和全尺寸键盘操作的手机。

但是传统手机都使用的是生产厂商自行开发的封闭式操作系统,所能实现的功能非常有限,不具备智能手机的扩展性。

从广义上讲,智能手机除了具备手机的通话功能外,还具备个人信息管理以及基于无线数据通信的浏览器、GPS(Global Positioning System)和电子邮件功能。

智能手机为用户提供了足够的屏幕尺寸和带宽,既方便随身携带,又为软件运行和内容服务提供个广阔的舞台,很多增值业务可以就此展开,如:股票、新闻、天气、交通、商品、应用程序下载、音乐图片下载等等。

结合3G通信网络的支持,智能手机的发展,势必将成为一个功能强大,集通话、短信、网络接入、影视娱乐为一体的综合性个人手持终端设备[3]。

1.1.2 课题意义随着通信技术的发展,3G从制定出到现在越来越被人们关注。

“3 G”(英语3rd-generation)或“三代”是第三代移动通信技术的简称,是指支持高速数据传输的蜂窝移动通信技术[4]。

目前3G存在四种标准:CDMA2000、WCDMATD-SCDMA、WiMAX。

其中TD-SCDMA (全称Time Division-Synchronous CDMA)是由中国大陆独自制定的3G标准。

为了推动我国的智能手机的发展,实现多功能的智能手机,方便人们丰富多彩而又快节奏的生活。

本文正是基于Android平台开发的计算机器。

论文主要阐述以面向对象的程序开发语言eclipse为开发工具, 基于智能手机Android之上设计一个计算器。

本文的目标就是设计并实现基于Android的计算器,论文首先介绍了Android开发平台和环境以及Android 工程的重要部分,然后着重针对计算器的系统设计和系统设计的具体实现,最后实现计算器的各种功能并得到了很多好的验证。

1.2 智能手机平台系统智能手机(Smartphone),是指“像个人电脑一样,具有独立的操作系统,可以由用户自行安装软件、游戏等第三方服务商提供的程序,通过此类程序来不断对手机的功能进行扩充,并可以通过移动通讯网络来实现无线网络接入的这样一类手机的总称”。

目前全球主要的只能手机操作系统依次是iPhone OS、Symbian、BlackBerry OS和Android,其中Android 最年轻,市场份额正迅速增加。

下面简单介绍Android以外的几款常用的智能手机系统。

IPhone OS是苹果公司专门为iPhone开发的智能手机系统[5]。

iPhone手机具有硬件与软件一一绑定的特性,Apple公司采用与运营商分成的策略。

iPhone虽然开放了SDK,可是却不能在PC上使用,这对于中国的应用开发市场是个不晓得阻碍。

但它将创新的移动电话、可触摸宽屏iPod以及具有桌面级电子邮件、网页浏览、搜索和地图功能的突破性因特网通信设备这三种产品完美的融合为一体的特性,也吸引了无数的用户。

Symbian(中文名:塞班)[6]是一个实时性、多任务的纯32位操作系统,具有功耗低、内存占用少等特点,非常适合手机等移动设备使用,经过不断完善,虽然在智能型手机市场取得了无比的成功,并长期居于首位,但是Symbian S60、Symbian3,UIQ等(尤其是S60)系统近两年亦遭遇到显著的发展瓶颈。

最近12个月欧洲手机公司诺基亚(Nokia)在智能手机市场市占率的滑落是不争的事实。

需要注意的是,并不是所有的Symbian系统都是智能系统,比如S40系统,就不属于智能手机系统。

BlackBerry OS[7]是RIM专用的智能手机操作系统。

BlackBerry,在美国市场占有率相对较高,BlackBerry的比较具有个性的设计就是宽大的屏幕和便于输入的QWERTY全键盘,所以BlackBerry在移动电子邮件方面非常方便,由于我国手机用户发送短信对于发送邮件,所以BlackBerry系统的邮件优势在中国不存在,目前BlackBerry OS在智能手机操作系统的市场份额占据第三位i,BlackBerry手机市场主要在美国[8]。

windows mobile是微软由于Pocket PC和Smartphone的软件平台[9]。

windows mobile 系统将大家熟悉的Windows桌面延伸到了移动设备中。

windows mobile是Microsoft为手持设备推出的“Windows移动版”。

受Android的冲击,目前Windows Mobile在智能手机操作系统的市场下降到4%左右。

Linux凭借其开放源代码、免费的优势,经过来自全球程序员的努力,再加上google、IBM等计算机巨头的支持。

相关文档
最新文档