andorid 计算器
avtivity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="6"
android:columnCount="4"
>
<!--rowCount 行数
columnCount 列数
layout_columnSpan 跨列
layout_rowSpan 跨行
fill_horizontal 水平填充
fill_vertical 垂直填充
layout_columnWeight 权重列
layout_rowWeight 权重行
background @drawable/ 设置图片
layout_row 指定行号
layout_column 指定列好 从0开始
-->
<EditText
android:layout_columnSpan="4"
android:layout_gravity="fill_horizontal"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:editable="false"
android:gravity="right|center_vertical"
android:id="@+id/et"/> <Button
android:text="清除"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
android:id="@+id/clear"
/>
<Button
android:text="后退"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
android:id="@+id/goback"/> <Button
android:text="/"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="X"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="7"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
android:id="@+id/bt_7"/>
<Button
android:text="8"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
android:id="@+id/bt_8"/>
<Button
android:text="9"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
android:id="@+id/bt_9"/>
<Button
android:text="-"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="4"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="5"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="6"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="+"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"/>
<Button
android:text="="
android:layout_rowSpan="2"
android:layout_gravity="fill_vertical"
android:layout_columnWeight="1"
android:layout_rowWeight="2"
android:textSize="25sp"
android:background="#24f"
/>
<Button
android:text="0"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
android:layout_columnWeight="2"
android:layout_rowWeight="1"
android:textSize="25sp"
/>
<Button
android:text="."
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:textSize="25sp"
/> </GridLayout>
CalculatorActivity
package com.hanqi.application3; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; /**
* Created by Administrator on 2016/3/28.
*/
public class CalculatorActivity extends Activity implements View.OnClickListener {
EditText et;
Button bt_clear;
Button bt_goback;
Button bt_7;
Button bt_8;
Button bt_9;
//构建字符串StringBuffer
//存储显示的内容
private StringBuffer str_show= new StringBuffer(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.avtivity_main); et=(EditText)findViewById(R.id.et);
bt_clear=(Button)findViewById(R.id.clear);
bt_7=(Button)findViewById(R.id.bt_7);
bt_8=(Button)findViewById(R.id.bt_8);
bt_9=(Button)findViewById(R.id.bt_9); bt_clear.setOnClickListener(this);
bt_goback.setOnClickListener(this);
bt_7.setOnClickListener(this);
bt_8.setOnClickListener(this);
bt_9.setOnClickListener(this); } public void onClick(View v)
{
Button bt = (Button)v; int id =bt.getId();
switch (id)
{
case R.id.clear:
str_show= new StringBuffer();
et.setText(str_show);
break;
case R.id.goback:
str_show.codePointAt(str_show.length()-1);
et.setText(str_show);
break;
case R.id.bt_7:
case R.id.bt_8:
case R.id.bt_9:
str_show.append(bt.getText());
et.setText(str_show);
break; }
}
}
andorid 计算器的更多相关文章
- 1.C#WinForm基础制作简单计算器
利用c#语言编写简单计算器: 核心知识点: MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号 MessageBox.S ...
- 自己动手写计算器v1.1
这个改动主要是使用工厂模式替代了简单工厂模式,这样做的好处是如果以后我们要扩充其他运算时,就不用总是去修改工厂类, 这是可以采取工厂模式,主要是将原来简单工厂类的逻辑判断分离出来,将它作为一个借口,与 ...
- 自己动手写计算器v1.0
今天突发奇想,想着看了还几个设计模式了,倒不如写点东西来实践它们.发现计算器这种就比较合适,打算随着设计模式的学习,会对计算器不断的做改进. 包括功能的增加和算法的改进.初学者难免犯错,希望大家不吝指 ...
- 【IOS开发笔记03-视图相关】简单计算器的实现
UIView 经过前几天的快速学习,我们初步了解的IOS开发的一些知识,中间因为拉的太急,忽略了很多基础知识点,这些知识点单独拿出来学习太过枯燥,我们在今后的项目中再逐步补齐,今天我们来学习APP视图 ...
- [LeetCode] Basic Calculator 基本计算器
Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...
- JS-自制提速小工具:开发页面时需要按比例计算宽高值的快速计算器
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <meta name= ...
- 由ArcMap属性字段自增引出字段计算器使用Python的技巧
1.前言 前些日子有人问我ArcMap中要让某个字段的值实现自增有什么方法?我首先想到像SQL Server中对于数值型字段可以设置自增.所以我打开ArcCatalog查看发现只提供默认值 ...
- 前端学PHP之面向对象系列第六篇——简单图形面积计算器实现
前面的话 本文用面向对象的技术来实现一个简单的图形面积计算器 图形类 //rect.class.php <?php abstract class Shape{ public $name; abs ...
- tn文本分析语言(四) 实现自然语言计算器
tn是desert和tan共同开发的一种用于匹配,转写和抽取文本的语言.解释器使用Python实现,代码不超过1000行. github地址:https://github.com/ferventdes ...
随机推荐
- GIS案例学习笔记-CAD数据分层导入现有模板实例教程
GIS案例学习笔记-CAD数据分层导入现有模板实例教程 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 1. 原始数据: CAD数据 目标模板 2. 任务:分5个图层 ...
- python基础学习Day10 函数形参的动态参数、*args **kwargs 命名空间 global 与 nonlocal
一.函数形参的动态参数 原因:为了拓展,对于实参数量不固定,故需要万能参数,即动态参数, *args **kwargs # def sum1(*args): # 在函数定义时,在*位置参数,聚合. ...
- for嵌套
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 学习BOS物流项目第十天
1 教学计划 1.演示权限demo 2.权限概述 a. 认证 b. 授权 3.常见的权限控制方式 a. url拦截权限控制 b. 方法注解权限控制 4.创建权限数据模型 a. 权限表 b. 角 ...
- K-means算法的实现
K-MEANS算法是一种经典的聚类算法,在模式识别得到了广泛的应用.算法中有两个关键问题需要考虑:一是如何评价对象的相似性,通常用距离来度量,距离越近越相似:另外一个是如何评价聚类的效果,通常采用误差 ...
- iframe解决ajax主域和子域之间的跨域问题
在某些应用场景下,需要在主域中,调用子域中的某个接口,如果直接在主域中向子域发ajax请求,会报跨域错误,可以用iframe来解决这种跨域问题.假如主域为www.baidu.com,子域为baike. ...
- OWAPSP_ZAP使用
启动OWAPSP_ZAP后 netstat -pantu | grep 8080
- vmware 完全关闭时间同步
参考 http://blog.51cto.com/hezhang/1535577 修改.vmx文件 tools.syncTime = "FALSE" time.synchroniz ...
- 【pyspider】启动爬虫后在results页面没有看到结果
今天根据书上的介绍写了一个简单爬虫,爬取豌豆荚里面APP的基本信息,但是在调试结果正常后,发现跳转到result页面后没有看到结果. 后来上网查了一下,发现要在def detail_page(self ...
- flash Air 在同一个目录下面创建txt,写入字
import flash.filesystem.*; var file:File=new File(File.applicationDirectory.nativePath + '/HelloWorl ...