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 ...
随机推荐
- c++之enum的好处与 define 的区别
转载自 https://blog.csdn.net/zhh464626057/article/details/41038933 什么时候需要用到enum呢?就是变量的数值在几个范围之间.red,blu ...
- 解决ngui挡住粒子的问题
using UnityEngine; using System.Collections; [ExecuteInEditMode] public class ControlParticle : Mono ...
- 学Android开发的人可以去的几个网站
学Android开发的人可以去的几个网站 1.<IT蓝豹>Android开源项目分享平台国内非常好的一个Android开发者分享站,分享android所有特效,每天都有最新的Android ...
- CommonJS/AMD/CMD/UMD
为什么会有这几种模式? 起源:Javascript模块化 模块化就是把复杂问题分解成不同模块,这样可维护性高,从而达到高复用,低耦合. 1.Commonjs CommonJS是服务器端模块的规范,No ...
- easyui-属性表格-easyui-propertygrid-列名显示英文官方文档无修改方案
修改值name value值为中文示例步骤: 1.<table 中 class="easyui-propertygrid" 中的data-options属性中加入 c ...
- The APK failed to install. Error:Could not parse error string.
问题一: The APK failed to install. Error:Could not parse error string. 今天拖拽自己的apk到模拟器上运行,报上述错误. 搜索解决方案. ...
- MyBatis数据库连接的基本使用-补充
补充1 MyBatis使用过程中,返回值类型可能是Map,不一定是实体类 返回查询结果也可以是一个Map,不一定是实体类 (1)mybatis会先将查询结果返回为一个map,字段名作为key,字段值 ...
- 游戏AI技术
[Unity3D人工智能编程精粹] 1.运动层.决策层.战略层. 运动层.决策层包含的算法是针对单个角色的,战略层是针对小队乃至更大规模群体的. 导航和寻路是运行层的主要任务. 决策层决定角色下一时间 ...
- GreaseMonkey开发(一):第一个自定义插件Hello GreaseMonkey!
GreaseMonkey最好在火狐浏览器上使用,下载好GreaseMonkey,重启浏览器右上角会出现一只小猴子. 新建一个脚本. 确定,填入代码保存. // ==UserScript== // @n ...
- msf客户端渗透(五):注册表
先获取到一个session 上传nc到被攻击主机上 建立一个键值 创建一个策略 kali上查看是否成功创建键值 后台开启cmd 查看防火墙的策略 打开防火墙的端口 添加一条防火墙策略 在win7上查看 ...