UI事件 计算器界面
1.MainActivity.java
package com.example.administrator.testapp2; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { TextView tv_1; Button bt1;
Button bt2;
Button bt3;
Button bt4;
Button bt5;
Button bt6;
Button bt7;
Button bt8;
Button bt9;
Button bt0;
Button bt_add;
Button bt_jian;
Button bt_cheng;
Button bt_chu;
Button bt_kuohao;
Button bt_dian; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); tv_1 = (TextView)findViewById(R.id.tv_1); bt0 = (Button)findViewById(R.id.bt0);
bt0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("0");
}
});
bt1 = (Button)findViewById(R.id.bt1);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("1");
}
});
bt2 = (Button)findViewById(R.id.bt2);
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("2");
}
});
bt3 = (Button)findViewById(R.id.bt3);
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("3");
}
});
bt4 = (Button)findViewById(R.id.bt4);
bt4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("4");
}
});
bt5 = (Button)findViewById(R.id.bt5);
bt5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("5");
}
});
bt6 = (Button)findViewById(R.id.bt6);
bt6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("6");
}
});
bt7 = (Button)findViewById(R.id.bt7);
bt7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("7");
}
});
bt8 = (Button)findViewById(R.id.bt8);
bt8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("8");
}
});
bt9 = (Button)findViewById(R.id.bt9);
bt9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("9");
}
});
bt_add = (Button)findViewById(R.id.bt_add);
bt_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("+");
}
});
bt_jian = (Button)findViewById(R.id.bt_jian);
bt_jian.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("-");
}
});
bt_cheng = (Button)findViewById(R.id.bt_cheng);
bt_cheng.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("X");
}
});
bt_chu = (Button)findViewById(R.id.bt_chu);
bt_chu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("÷");
}
});
bt_dian = (Button)findViewById(R.id.bt_dian);
bt_dian.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText(".");
}
});
bt_kuohao = (Button)findViewById(R.id.bt_kuohao);
bt_kuohao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_1.setText("()");
}
});
}
}
2.jsq.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="5"
android:columnCount="4">
<TextView
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_columnSpan="4"
android:textSize="60dp"
android:gravity="right|bottom"
android:text="6"
android:textColor="#0F0"
android:paddingRight="10dp"
android:id="@+id/tv_1"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CE"
android:layout_rowWeight="1"
android:id="@+id/bt_CE"
android:textSize="25sp"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="←"
android:id="@+id/bt_qc"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="÷"
android:id="@+id/bt_chu"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X"
android:id="@+id/bt_cheng"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/bt7"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/bt8"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/bt9"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/bt_jian"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/bt4"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/bt5"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/bt6"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/bt_add"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/bt1"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/bt2"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/bt3"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:id="@+id/btdengyu"
android:textSize="25sp"
android:layout_columnWeight="1"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:layout_gravity="fill"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/bt0"
android:textSize="25sp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/bt_dian"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="()"
android:id="@+id/bt_kuohao"
android:textSize="25sp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"/>
</GridLayout>
UI事件 计算器界面的更多相关文章
- UI事件监听的击穿
什么是UI事件监听的击穿 在游戏视图中,有两个UI界面叠在一起的时候,单击一个空白处,却触发了被覆盖在下层了UI界面中的单击事件,这就是单击击穿了上层界面. 假设场景中放置了一个箱子,单击箱子会触发一 ...
- Android学习笔记--处理UI事件
Handling UI Events 在Android里, 有不只一种方式可以截获用户与你的应用程序交互的事件. 在你的界面上处理事件时,你需要捕获用户与某个View实例交互时所产生的事件.View类 ...
- Java按钮控件数组实现计算器界面
编写程序,通过按钮数组来管理界面中的所有按钮控件,从而使用最少的代码实现模拟的计算器界面. 思路如下: 创建一个类,通过extends使其继承窗体类JFrame: 创建一个JFrame对象,使用JFr ...
- [Xcode 实际操作]七、文件与数据-(23)UI Testing系统界面测试功能的使用
目录:[Swift]Xcode实际操作 本文将演示UI Testing系统界面测试功能的使用. 如果项目中尚未引入界面测试功能,请点击项目属性面板->[General]面板左下角的[+]图标 - ...
- 免费素材:25套免费的 Web UI 设计的界面元素(转)
Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. ...
- UI事件之load
load事件属于CSS3规范中的UI事件,load事件处理程序在页面元素和资源(html/script/link/img等)全部加载完成后在window上触发,或在img元素加载完成后再img元素上触 ...
- Javascript高级编程学习笔记(61)—— 事件(5)UI事件
UI事件 UI事件是指那些不一定与用户操作有关的事件 这些事件在DOM规范出现之前,都是以各种不同的形式存在于不同的浏览器 而在DOM事件中为了保证向后兼容,现有的UI事件如下: DOMActivat ...
- Xamarin XAML语言教程将XAML设计的UI显示到界面
Xamarin XAML语言教程将XAML设计的UI显示到界面 如果通过XAML将UI设计好以后,就可以将XAML中的内容显示给用户了,也就是显示到界面上.由于创建XAML文件方式的不同,所以将XAM ...
- UI事件与内容,舞台与演员
UI事件:创建/清除/显示/隐藏/填充内容/位置变化/形态变化/尺寸变化/颜色变化/ 非UI事件:点击/输入/拖动/
随机推荐
- struts2中的ognl详解,摘抄
http://blog.csdn.net/tjcyjd/article/details/6850203 很全很细致,自己再分析原理进阶
- 夺命雷公狗---node.js---8url模块和util模块
我们先到手册上看看: 上面很明显就写着返回一个对象. 再来看看util模块, 废话不哦多说,先上一点代码: /** * Created by leigood on 2016/8/13. */ var ...
- Sql Server Analysis Service 转换为UnknownMember的正确设置
在SSAS中事实表数据被归类到为UnknownMember 的时候分为两种情况: 第一种情况,在SSAS里面事实表中的外键是null,这种情况SSAS在建事实表和维度时ErrorConfigurati ...
- WebService优点和缺点小结(转)
一.什么是WebService? 实际上,WebService的主要目标是跨平台的可互操作性.为了达到这一目标,WebService完全基于XML(可扩展标记语言).XSD (XMLSchema) ...
- 读 《JavaScript: The Good Parts》 有感
提炼出一门语言或技术的 Good Parts, 使用该子集去构造健壮稳固的应用. 我们总是倾向于去学习和使用所有的语言特性,好像凡是新的,凡是提供了的, 就有必要去使用: 这本书告诉我们, 要有选择性 ...
- EL表达式,JSTL:jsp standard Tag Library
1.EL表达式的作用: 1.1访问Bean的属性. 方式一:${对象名 . 属性名} eg:${user.name} 方式二:${对象名["属性名"]} 1.2输出简单的运 ...
- linux下用core和gdb查询出现"段错误"的地方【转】
转自:http://blog.chinaunix.net/uid-30091091-id-5754288.html 原文地址:linux下用core和gdb查询出现"段错误"的地方 ...
- oracle 创建表空间用户
1.创建普通表空间和用户 //创建临时表空间create temporary tablespace oa_temptempfile 'D:\app\Administrator\oradata\orcl ...
- Oracle 临时表
一.临时表的介绍: Oracle的临时表只存在于某个会话或者事物的生命周期里,此时临时表中的数据只对当前这个会话可见. 临时表经常被用于存放一个操作的中间数据(数据处理的中间环节). 临时表由于不产生 ...
- Mysql slow query log
一.概念部分: 顾名思义,慢查询日志中记录的是执行时间较长的query,也就是我们常说的slow query,通过设--log-slow-queries[=file_name]来打开该功能并设置记录 ...