计算器Android版源码文档格式.docx
- 文档编号:17087092
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:17
- 大小:43.40KB
计算器Android版源码文档格式.docx
《计算器Android版源码文档格式.docx》由会员分享,可在线阅读,更多相关《计算器Android版源码文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
orientation="
vertical"
>
<
TableLayout
id="
@+id/tableLayout1"
match_parent"
wrap_content"
collapseColumns="
4"
TableRow
@+id/tableRow_et"
EditText
@+id/et"
layout_span="
focusable="
false"
singleLine="
true"
inputType="
text"
gravity="
right"
/EditText>
/TableRow>
@+id/tableRow1"
Button
@+id/bt_7"
40px"
text="
7"
/>
@+id/bt_8"
8"
@+id/bt_9"
9"
@+id/bt_back"
back"
@+id/tableRow2"
@+id/bt_4"
@+id/bt_5"
5"
@+id/bt_6"
6"
@+id/bt_divide"
/"
@+id/tableRow3"
@+id/bt_1"
1"
@+id/bt_2"
2"
@+id/bt_3"
3"
@+id/bt_multiply"
*"
@+id/tableRow4"
@+id/bt_0"
50px"
0"
@+id/bt_point"
."
@+id/bt_add"
+"
@+id/bt_sub"
-"
@+id/bt_equal"
="
@+id/bt_clear"
clear"
/TableLayout>
/LinearLayout>
源代码:
packageandroid.sdk;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
publicclassAndroid_calculatorActivityextendsActivity
{
privateButtonbt_1;
privateButtonbt_2;
privateButtonbt_3;
privateButtonbt_4;
privateButtonbt_5;
privateButtonbt_6;
privateButtonbt_7;
privateButtonbt_8;
privateButtonbt_9;
privateButtonbt_0;
privateButtonbt_add;
privateButtonbt_sub;
//减
privateButtonbt_multiply;
//乘
privateButtonbt_divide;
//除
privateButtonbt_back;
privateButtonbt_equal;
//等于
privateButtonbt_point;
//点
privateButtonbt_clear;
//清除
privateEditTextet_play;
//显示
privateStringstr_oper="
;
//运算符
privateStringBufferstr_display=newStringBuffer();
privateStringstr_result;
//结果显示
privatedoublenum1;
privatedoublenum2;
privatebooleanflag=true;
//小数点个数开关控制;
privatebooleanb_sub,b_mul,b_div;
//运算符开关控制
@Override
publicvoidonCreate(BundlesavedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt_0=(Button)findViewById(R.id.bt_0);
bt_1=(Button)findViewById(R.id.bt_1);
bt_2=(Button)findViewById(R.id.bt_2);
bt_3=(Button)findViewById(R.id.bt_3);
bt_4=(Button)findViewById(R.id.bt_4);
bt_5=(Button)findViewById(R.id.bt_5);
bt_6=(Button)findViewById(R.id.bt_6);
bt_7=(Button)findViewById(R.id.bt_7);
bt_8=(Button)findViewById(R.id.bt_8);
bt_9=(Button)findViewById(R.id.bt_9);
bt_add=(Button)findViewById(R.id.bt_add);
bt_sub=(Button)findViewById(R.id.bt_sub);
bt_multiply=(Button)findViewById(R.id.bt_multiply);
bt_divide=(Button)findViewById(R.id.bt_divide);
bt_back=(Button)findViewById(R.id.bt_back);
bt_equal=(Button)findViewById(R.id.bt_equal);
bt_point=(Button)findViewById(R.id.bt_point);
bt_clear=(Button)findViewById(R.id.bt_clear);
et_play=(EditText)findViewById(R.id.et);
et_play.setText("
0.0"
);
bt_0.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("
et_play.setText(str_display.toString());
}
});
bt_1.setOnClickListener(newOnClickListener()
bt_2.setOnClickListener(newOnClickListener()
bt_3.setOnClickListener(newOnClickListener()
bt_4.setOnClickListener(newOnClickListener()
bt_5.setOnClickListener(newOnClickListener()
bt_6.setOnClickListener(newOnClickListener()
bt_7.setOnClickListener(newOnClickListener()
bt_8.setOnClickListener(newOnClickListener()
bt_9.setOnClickListener(newOnClickListener()
bt_point.setOnClickListener(newOnClickListener()
if(flag)
{
str_display.append("
flag=false;
}
bt_back.setOnClickListener(newOnClickListener()
if(str_display.length()!
=0)
str_display.deleteCharAt(str_display.length()-1);
et_play.setText(str_display.toString());
bt_add.setOnClickListener(newOnClickListener()
str_oper="
if(!
(str_display.toString()=="
"
))
num1+=Double.parseDouble(str_display.toString());
str_display=newStringBuffer("
(str_result==null))
num1=Double.parseDouble(str_result);
str_result=null;
et_play.setText(String.valueOf(num1));
flag=true;
bt_sub.setOnClickListener(newOnClickListener()
b_sub&
&
!
num1=Double.parseDouble(str_display.toString());
et_play.setText(String.valueOf(num1));
b_sub=true;
}else
if(!
{
num1-=Double.parseDouble(str_display.toString());
str_display=newStringBuffer("
}
num1=Double.parseDouble(str_result);
str_result=null;
bt_multiply.setOnClickListener(newOnClickListener()
b_mul&
b_mul=true;
if
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算器 Android 源码