简单的android计算器.docx

上传人:b****5 文档编号:14595885 上传时间:2023-06-24 格式:DOCX 页数:20 大小:133.31KB
下载 相关 举报
简单的android计算器.docx_第1页
第1页 / 共20页
简单的android计算器.docx_第2页
第2页 / 共20页
简单的android计算器.docx_第3页
第3页 / 共20页
简单的android计算器.docx_第4页
第4页 / 共20页
简单的android计算器.docx_第5页
第5页 / 共20页
简单的android计算器.docx_第6页
第6页 / 共20页
简单的android计算器.docx_第7页
第7页 / 共20页
简单的android计算器.docx_第8页
第8页 / 共20页
简单的android计算器.docx_第9页
第9页 / 共20页
简单的android计算器.docx_第10页
第10页 / 共20页
简单的android计算器.docx_第11页
第11页 / 共20页
简单的android计算器.docx_第12页
第12页 / 共20页
简单的android计算器.docx_第13页
第13页 / 共20页
简单的android计算器.docx_第14页
第14页 / 共20页
简单的android计算器.docx_第15页
第15页 / 共20页
简单的android计算器.docx_第16页
第16页 / 共20页
简单的android计算器.docx_第17页
第17页 / 共20页
简单的android计算器.docx_第18页
第18页 / 共20页
简单的android计算器.docx_第19页
第19页 / 共20页
简单的android计算器.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

简单的android计算器.docx

《简单的android计算器.docx》由会员分享,可在线阅读,更多相关《简单的android计算器.docx(20页珍藏版)》请在冰点文库上搜索。

简单的android计算器.docx

简单的android计算器

 

核心算法步骤如下:

输入:

传感矩阵

,采样向量

,稀疏度

输出:

-稀疏逼近

初始化:

残差

索引集

循环执行步骤1—5:

步骤一:

找出残差

与传感矩阵的列

积中最大值所对应的的脚注

,即

步骤2:

更新索引集

,记录找到的传感矩阵中的重建原子集合

步骤3:

由最小二乘法得到

步骤4:

更新残差

步骤5:

判断是否满足

若满足则迭代停止;若不满足,则执行步骤1.

 

基于android的简单计算器

1、界面截图

2、布局文件

总体是一个LinearLayout布局,每一行的按钮也使用了此布局.当然,每一行也可以在TableLayout里使用TableRow。

虽然使用其他布局可能会简洁点,不过我个人喜欢使用LinearLayout布局。

android="http:

//schemas.android。

com/apk/res/android"

xmlns:

tools="http:

//schemas。

android:

orientation=”vertical"

android:

layout_width=”match_parent"

android:

layout_height=”match_parent"〉

〈EditText

android:

id="@+id/et_input"

android:

layout_width=”fill_parent"

android:

layout_height="wrap_content"

android:

maxLength=”25”

android:

textColor=”#00ff00”

android:

cursorVisible=”false"

android:

gravity="right”

android:

text="0”/>

 〈!

—-android:

cursorVisible="false"输入框中光标不可见——〉

   <!

——android:

gravity=”right"输入内容从右边开始显示—->

〈LinearLayout

android:

layout_width="fill_parent"

android:

layout_height=”wrap_content”

android:

paddingRight=”5dp"

android:

paddingLeft="5dp"

android:

orientation=”horizontal”〉

android:

id=”@+id/button_bk"

android:

layout_width=”0dp”

android:

layout_height="wrap_content"

android:

text="BK"

android:

layout_weight=”1"

/〉

android:

id="@+id/button_ce”

android:

layout_width="0dp"

android:

layout_height=”wrap_content”

android:

text="CE"

android:

layout_weight=”1”

/>

〈Button

android:

id="@+id/button_c"

android:

layout_width="0dp"

android:

layout_height="wrap_content"

android:

text=”C”

android:

layout_weight=”1”

/〉

〈/LinearLayout〉

android:

layout_width=”fill_parent”

android:

layout_height=”wrap_content"

android:

paddingRight="5dp”

android:

paddingLeft=”5dp”

android:

orientation="horizontal">

〈Button

android:

id="@+id/button_mc”

android:

layout_width="0dp”

android:

layout_height="wrap_content"

android:

text="MC"

android:

layout_weight=”1"

/〉

〈Button

android:

id="@+id/button_7”

android:

layout_width="0dp”

android:

layout_height="wrap_content"

android:

text=”7"

android:

layout_weight=”1"

/〉

〈Button

android:

id="@+id/button_8"

android:

layout_width=”0dp"

android:

layout_height=”wrap_content"

android:

text="8”

android:

layout_weight="1"

/>

android:

id="@+id/button_9"

android:

layout_width="0dp”

android:

layout_height=”wrap_content”

android:

text="9”

android:

layout_weight=”1"

/〉

〈Button

android:

id=”@+id/button_div”

android:

layout_width=”0dp"

android:

layout_height="wrap_content"

android:

text=”/”

android:

layout_weight=”1"

/〉

〈LinearLayout

android:

layout_width="fill_parent”

android:

layout_height="wrap_content"

android:

paddingRight="5dp”

android:

paddingLeft=”5dp"

android:

orientation="horizontal”〉

〈Button

android:

id="@+id/button_mr"

android:

layout_width=”0dp"

android:

layout_height=”wrap_content"

android:

text=”MR"

android:

layout_weight=”1”

/〉

android:

id="@+id/button_4”

android:

layout_width=”0dp"

android:

layout_height=”wrap_content”

android:

text="4"

android:

layout_weight="1"

/>

android:

id="@+id/button_5"

android:

layout_width="0dp”

android:

layout_height="wrap_content”

android:

text=”5"

android:

layout_weight=”1”

/>

〈Button

android:

id="@+id/button_6"

android:

layout_width=”0dp"

android:

layout_height=”wrap_content”

android:

text=”6"

android:

layout_weight=”1"

/>

android:

id="@+id/button_multi"

android:

layout_width=”0dp”

android:

layout_height=”wrap_content”

android:

text="*"

android:

layout_weight="1”

/〉

〈LinearLayout

android:

layout_width=”fill_parent"

android:

layout_height="wrap_content”

android:

paddingRight=”5dp”

android:

paddingLeft="5dp"

android:

orientation=”horizontal”〉

android:

id="@+id/button_ms"

android:

layout_width=”0dp"

android:

layout_height=”wrap_content"

android:

text="MS”

android:

layout_weight="1"

/>

〈Button

android:

id="@+id/button_1"

android:

layout_width=”0dp”

android:

layout_height="wrap_content"

android:

text=”1"

android:

layout_weight="1”

/>

android:

id="@+id/button_2”

android:

layout_width=”0dp”

android:

layout_height=”wrap_content”

android:

text="2"

android:

layout_weight="1"

/>

〈Button

android:

id=”@+id/button_3"

android:

layout_width="0dp”

android:

layout_height="wrap_content”

android:

text="3"

android:

layout_weight=”1"

/〉

android:

id="@+id/button_minus"

android:

layout_width="0dp”

android:

layout_height="wrap_content"

android:

text="-"

android:

layout_weight="1”

/>

〈/LinearLayout〉

〈LinearLayout

android:

layout_width="fill_parent”

android:

layout_height=”wrap_content"

android:

paddingRight=”5dp”

android:

paddingLeft=”5dp”

android:

orientation="horizontal”〉

android:

id=”@+id/button_sign"

android:

layout_width="0dp"

android:

layout_height=”wrap_content"

android:

text=”+/-”

android:

layout_weight="1”

/>

android:

id="@+id/button_equal”

android:

layout_width="0dp”

android:

layout_height="wrap_content"

android:

text="="

android:

layout_weight="1"

/>

〈Button

android:

id=”@+id/button_0”

android:

layout_width="0dp”

android:

layout_height=”wrap_content"

android:

text=”0"

android:

layout_weight=”1"

/>

android:

id=”@+id/button_dot"

android:

layout_width="0dp"

android:

layout_height="wrap_content"

android:

text=”。

android:

layout_weight="1”

/>

android:

id="@+id/button_plus”

android:

layout_width=”0dp”

android:

layout_height=”wrap_content”

android:

text="+”

android:

layout_weight="1”

/〉

〈/LinearLayout>

〈TextView

android:

id=”@+id/tv_tmp”

android:

layout_width="wrap_content”

android:

layout_height=”wrap_content”

android:

textColor=”@color/pink”

android:

text=”Memory=”/〉

android:

id="@+id/tv_mem"

android:

layout_width=”wrap_content”

android:

layout_height="wrap_content”

android:

textColor=”@color/sliver"

android:

text=”0”/〉

〈!

-—显示记忆数据——〉

 

布局文件中在TextView和EditText中使用的Color要在strings。

xml中定义。

Calculator〈/string〉

〈/string〉

#ffc0cb〈/color>

#c0c0c0

 

3、java代码:

各种组件的使用在代码里都有明确说明,在此不再说明.

packagecom.example。

calculator;

importandroid.os.Bundle;

importandroid。

app。

Activity;

importandroid。

view.Menu;

importandroid。

view。

View;

importandroid。

view.View.OnClickListener;

importandroid。

widget。

Button;

importandroid.widget。

EditText;

importandroid.widget。

TextView;

publicclassMyCalculatorextendsActivity{

doubleop1=0,op2=0;//记录两次输入的值

charoperation;//记录运算符

EditTextinput;//输入文本框

booleanisInputChar=false;//判断是否输入了运算符

TextViewmemory;//记忆文本

Buttonplus,minus,multi,divide,equal;//运算符

Buttonback,clean,cleanAll;//文本数据处理(回退、本次输

//入清零、所有输入清零)

Buttonmclean,mread,msave;//数据记忆(清除、读取、保存)

Button[]btn=newButton[10];//数字

Buttondot;//点

Buttonsign;//正负数转换

@Override

publicvoidonCreate(BundlesavedInstanceState){

super。

onCreate(savedInstanceState);

setContentView(R。

layout.activity_my_calculator);

input=(EditText)findViewById(R。

id。

et_input);

memory=(TextView)findViewById(R。

id.tv_mem);

//运算符

plus=(Button)findViewById(R。

id.button_plus);

minus=(Button)findViewById(R.id.button_minus);

multi=(Button)findViewById(R。

id。

button_multi);

divide=(Button)findViewById(R.id.button_div);

equal=(Button)findViewById(R。

id。

button_equal);

//设置点击监听

plus。

setOnClickListener(listener);

minus.setOnClickListener(listener);

multi。

setOnClickListener(listener);

divide。

setOnClickListener(listener);

equal。

setOnClickListener(listener);

//记忆

back=(Button)findViewById(R。

id。

button_bk);

clean=(Button)findViewById(R.id。

button_ce);

cleanAll=(Button)findViewById(R。

id。

button_c);

back。

setOnClickListener(listener);

clean。

setOnClickListener(listener);

cleanAll。

setOnClickListener(listener);

//数据记忆

mclean=(Button)findViewById(R。

id。

button_mc);

mread=(Button)findViewById(R。

id.button_mr);

msave=(Button)findViewById(R.id。

button_ms);

mclean.setOnClickListener(listener);

mread.setOnClickListener(listener);

msave.setOnClickListener(listener);

//数字

btn[0]=(Button)findViewById(R。

id。

button_0);

btn[1]=(Button)findViewById(R。

id。

button_1);

btn[2]=(Button)findViewById(R.id。

button_2);

btn[3]=(Button)findViewById(R。

id。

button_3);

btn[4]=(Button)findViewById(R。

id.button_4);

btn[5]=(Button)findViewById(R。

id。

button_5);

btn[6]=(Button)findViewById(R。

id.button_6);

btn[7]=(Button)findViewById(R。

id。

button_7);

btn[8]=(Button)findViewById(R。

id。

button_8);

btn[9]=(Button)findViewById(R。

id。

button_9);

for(inti=0;i<10;i++){

btn[i].setOnClickListener(listener);

//点

dot=(Button)findViewById(R。

id。

button_dot);

dot。

setOnClickListener(listener);

//正负数转换

sign=(Button)findViewById(R.id。

button_sign);

sign.setOnClickListener(listener);

}

//按钮监听

privateOnClickListenerlistener=newOnClickListener(){

publicvoidonClick(Viewv){

//TODOAuto—generatedmethodstub

//获取输入数据

StringinputText=input.getText().toString();

//对输入数据进行判断

switch(v。

getId()){

caseR。

id。

button_bk:

//后退

if(inputText。

length()>1)

input。

setText(inputText。

substring(0,inputText。

length()—1));

elseif(inputText.length()==1){

input.setText(”0”);

if(input.getText().toString()。

compareTo("-")==0){//去除负号

input。

setText("0”);

break;

caseR.id。

button_ce:

//此次输入清零

input。

setText(”0”);

if(isInputChar)

op2=0;

else

op1=0;

break;

caseR.id.button_c:

//全部清零,重新计算

input.setText(”0”);

op1=0;

op2=0;

isInputChar=false;

break;

caseR.id。

button_mc:

//清空记忆数据

memory.setText("0”);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 计算机硬件及网络

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2