android简单计算器代码Word格式.docx
- 文档编号:14078989
- 上传时间:2022-10-18
- 格式:DOCX
- 页数:12
- 大小:16.51KB
android简单计算器代码Word格式.docx
《android简单计算器代码Word格式.docx》由会员分享,可在线阅读,更多相关《android简单计算器代码Word格式.docx(12页珍藏版)》请在冰豆网上搜索。
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);
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。
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。
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。
but8.setOnClickListener(this);
but9。
but0.setOnClickListener(this);
dim。
}
@Override
publicvoidonClick(Viewv){
//TODOAuto-generatedmethodstub
if(v。
equals(but1)){
tem=tem+"
1”;
etext。
setText(tem);
}
if(v.equals(but2)){
2”;
etext.setText(tem);
}
equals(but3)){
3”;
setText(tem);
if(v.equals(but4)){
4”;
equals(but5)){
tem=tem+”5"
equals(but6)){
6”;
etext.setText(tem);
if(v.equals(but7)){
7”;
if(v.equals(but8)){
tem=tem+”8"
;
if(v.equals(but9)){
9”;
if(v.equals(but0)){
tem=tem+”0"
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;
/"
){
value=value/d;
+"
value=d+value;
}
setText("
"
);
if(arg。
equals(add)){
sign="
+”;
if(arg.equals(div)){
}
equals(mult)){
*”;
equals(sub)){
sign=”—"
tem=”"
}
classListenerimplementsOnClickListener{
@Override
str1=etext.getText()。
toString();
if(str1.equals("
doubled=Double。
parseDouble(str1);
a"
*"
value=value*d;
—”){
value=value-d;
value=value/d;
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_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- android 简单 计算器 代码