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事件:点击/输入/拖动/
随机推荐
- Oracle游标整理二
1.概念 游标是指向SQL处理的内存区的句柄或指针.当使用一个PL/SQL块来执行DML语句或只返回一行结果的SELECT语句时,系统将自动创建一个隐式游标.如果SQL语句返回多个结果,就必须 ...
- 【cruch bang】中切换成左手鼠标
在“右键”菜单->settings->Edit autostart启动的geany编辑器中,最后加内容: xmodmap -e 'pointer = 3 2 1'
- xx
[git]merge和rebase的区别 - 削微寒 - 博客园 http://www.cnblogs.com/vamei/p/3480994.html 协议森林16 小美的桌号(DHCP协议) - ...
- andoid下的股票行情开发
1.信息类 public class SinaStockInfo { /** * Sina股票数据接口 以大秦铁路(股票代码:601006)为例,如果要获取它的最新行情,只需访问新浪的股票数据 * 接 ...
- Java中Properties类的使用
1.properties介绍 java中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值&quo ...
- Understanding the RelationshipType Enumeration [AX 2012]
Understanding the RelationshipType Enumeration [AX 2012] 3 out of 3 rated this helpful - Rate this t ...
- POJ 3237:Tree(树链剖分)
http://poj.org/problem?id=3237 题意:树链剖分.操作有三种:改变一条边的边权,将 a 到 b 的每条边的边权都翻转(即 w[i] = -w[i]),询问 a 到 b 的最 ...
- bootstrap/moban191/js/templatemo_custom.js
(function($) { "use strict"; // Cache selectors var lastId, topMenu = $(".menu-holder ...
- python:用json把字典序列化到文件中
#写程序最好是dump一次和load一次,可以存好几个文件 import json info={'name':'Tom', 'age':'12', 'job':'work',} f=open('fil ...
- 使用KNN对MNIST数据集进行实验
由于KNN的计算量太大,还没有使用KD-tree进行优化,所以对于60000训练集,10000测试集的数据计算比较慢.这里只是想测试观察一下KNN的效果而已,不调参. K选择之前看过貌似最好不要超过2 ...