android简单计算器代码.docx

上传人:b****3 文档编号:1159886 上传时间:2022-10-18 格式:DOCX 页数:12 大小:16.51KB
下载 相关 举报
android简单计算器代码.docx_第1页
第1页 / 共12页
android简单计算器代码.docx_第2页
第2页 / 共12页
android简单计算器代码.docx_第3页
第3页 / 共12页
android简单计算器代码.docx_第4页
第4页 / 共12页
android简单计算器代码.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

android简单计算器代码.docx

《android简单计算器代码.docx》由会员分享,可在线阅读,更多相关《android简单计算器代码.docx(12页珍藏版)》请在冰豆网上搜索。

android简单计算器代码.docx

android简单计算器代码

android简单计算器代码

 

 

————————————————————————————————作者:

————————————————————————————————日期:

 

packagehua.xing.demo;

importandroid。

app。

Activity;

importandroid。

os。

Bundle;

importandroid.view。

View;

importandroid.view.View.OnClickListener;

importandroid。

widget.Button;

importandroid.widget。

EditText;

publicclassCalculatordemoActivityextendsActivityimplementsOnClickListener{

/**Calledwhentheactivityisfirstcreated。

*/

privateButtonbut0=null;

privateButtonbut1=null;

privateButtonbut2=null;

privateButtonbut3=null;

privateButtonbut4=null;

privateButtonbut5=null;

privateButtonbut6=null;

privateButtonbut7=null;

privateButtonbut8=null;

privateButtonbut9=null;

privateButtondim=null;

privateButtonadd=null;

privateButtonsub=null;

privateButtonmult=null;

privateButtondiv=null;

privateButtonequ=null;

privateEditTextetext=null;

privatedoublevalue=0;

privateStringstr1=null;

privateStringtem=””;

privateStringsign=”a";

@Override

publicvoidonCreate(BundlesavedInstanceState){

super。

onCreate(savedInstanceState);

super。

setContentView(R。

layout。

main);

add=(Button)findViewById(R.id。

add);

sub=(Button)findViewById(R。

id.sub);

mult=(Button)findViewById(R。

id.mult);

div=(Button)findViewById(R。

id。

divid);

equ=(Button)findViewById(R.id。

caculate);

but1=(Button)findViewById(R。

id.but1);

but3=(Button)findViewById(R.id.but3);

but2=(Button)findViewById(R.id.but2);

but4=(Button)findViewById(R.id.but4);

but5=(Button)findViewById(R.id.but5);

but6=(Button)findViewById(R.id。

but6);

but7=(Button)findViewById(R。

id。

but7);

but8=(Button)findViewById(R.id。

but8);

but9=(Button)findViewById(R。

id.but9);

but0=(Button)findViewById(R.id.but0);

dim=(Button)findViewById(R。

id.dim);

etext=(EditText)findViewById(R.id。

etext);

add。

setOnClickListener(newAListener());

sub。

setOnClickListener(newAListener());

mult.setOnClickListener(newAListener());

div。

setOnClickListener(newAListener());

equ。

setOnClickListener(newListener());

but1.setOnClickListener(this);

but3。

setOnClickListener(this);

but2.setOnClickListener(this);

but4。

setOnClickListener(this);

but5.setOnClickListener(this);

but6.setOnClickListener(this);

but7。

setOnClickListener(this);

but8.setOnClickListener(this);

but9。

setOnClickListener(this);

but0.setOnClickListener(this);

dim。

setOnClickListener(this);

@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub

if(v。

equals(but1)){

tem=tem+"1”;

etext。

setText(tem);

if(v.equals(but2)){

tem=tem+"2”;

etext.setText(tem);

}

if(v。

equals(but3)){

tem=tem+"3”;

etext。

setText(tem);

if(v.equals(but4)){

tem=tem+"4”;

etext。

setText(tem);

if(v。

equals(but5)){

tem=tem+”5";

etext。

setText(tem);

if(v。

equals(but6)){

tem=tem+"6”;

etext.setText(tem);

if(v.equals(but7)){

tem=tem+"7”;

etext.setText(tem);

}

if(v.equals(but8)){

tem=tem+”8";

etext.setText(tem);

if(v.equals(but9)){

tem=tem+"9”;

etext。

setText(tem);

if(v.equals(but0)){

tem=tem+”0";

etext。

setText(tem);

}

classAListenerimplementsOnClickListener{

@Override

publicvoidonClick(Viewarg){

//TODOAuto—generatedmethodstub

str1=etext.getText().toString();

if(str1.equals(”")){

}else{

doubled=Double.parseDouble(str1);

if(sign==”a"){

value=d;

if(sign==”*”){

value=value*d;

}

if(sign=="-”){

value=value—d;

}

if(sign=="/"){

value=value/d;

if(sign=="+"){

value=d+value;

}

}

etext。

setText("");

if(arg。

equals(add)){

sign="+”;

}

if(arg.equals(div)){

sign="/";

if(arg。

equals(mult)){

sign="*”;

if(arg。

equals(sub)){

sign=”—";

}

tem=”";

}

classListenerimplementsOnClickListener{

@Override

publicvoidonClick(Viewarg){

//TODOAuto—generatedmethodstub

str1=etext.getText()。

toString();

if(str1.equals("")){

}else{

doubled=Double。

parseDouble(str1);

if(sign=="a"){

value=d;

}

if(sign=="*"){

value=value*d;

if(sign=="—”){

value=value-d;

}

if(sign=="/"){

value=value/d;

if(sign=="+"){

value=d+value;

}

etext.setText(value+”");

sign=”a”;

value=0;

tem=””;

}

}

<?

xmlversion=”1.0”encoding="utf-8"?

〈RelativeLayoutxmlns:

android=”http:

//schemas.android。

com/apk/res/android"

android:

layout_width=”fill_parent"

android:

layout_height="fill_

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1