andorid简单计算器java源码_Android开发实现的简单计算器功能【附完整demo源码下载】...

本文实例讲述了Android开发实现的简单计算器功能。分享给大家供大家参考,具体如下:

这个Android计算器虽然还有点小bug,不过简单的计算功能还是没问题的哦;

先上图看效果

c2b8cec428d4b89782825314bb68a2c8.png

比较简单,所以我就没怎么写注释,应该一看就能明白的

有不明白的可以发信问我

先贴MainActivity.java代码

package com.example.calculator;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b0, bp, bs, bm, bd, bc, be;

ImageView delete;

TextView tv;

EditText show;

String showString = "", option = "";

int showfirst = 0;

String exception = "";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

b0 = (Button) findViewById(R.id.bt_0);

b1 = (Button) findViewById(R.id.bt_1);

b2 = (Button) findViewById(R.id.bt_2);

b3 = (Button) findViewById(R.id.bt_3);

b4 = (Button) findViewById(R.id.bt_4);

b5 = (Button) findViewById(R.id.bt_5);

b6 = (Button) findViewById(R.id.bt_6);

b7 = (Button) findViewById(R.id.bt_7);

b8 = (Button) findViewById(R.id.bt_8);

b9 = (Button) findViewById(R.id.bt_9);

bp = (Button) findViewById(R.id.bt_plus);

bs = (Button) findViewById(R.id.bt_sub);

bm = (Button) findViewById(R.id.bt_mutilate);

bd = (Button) findViewById(R.id.bt_div);

bc = (Button) findViewById(R.id.bt_c);

be = (Button) findViewById(R.id.bt_equ);

b1.setOnClickListener(this);

b2.setOnClickListener(this);

b3.setOnClickListener(this);

b4.setOnClickList

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值