欢迎来到天天文库
浏览记录
ID:39464551
大小:19.43 KB
页数:10页
时间:2019-07-03
《android开发计算器核心代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagecom.gem.android;importjava.util.ArrayList;importjava.util.List;importandroid.app.Activity;importandroid.os.Bundle;importandroid.text.InputType;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;/***程序主activity*@a
2、uthorszh*核心思想是把+左右部分分成两部分分别转化成double类型然后获得=的id*分别判断使用何种运算*/publicclassCaculatorActivityextendsActivityimplementsOnClickListener{/**Calledwhentheactivityisfirstcreated.*/privatestaticStringdate1=null;//声明静态变量date1,date2,operator;privatestaticStringdate2=null;privatestaticStringoperator=null
3、;privatestaticListl=newArrayList();//声明静态集合List;privatedoublex=0;//声明double型成员变量x,y,z;privatedoubley=0;privatedoublere=0;privateEditTextresult=null;//声明界面上所有控件;privateButtonequal=null;privateButtonadd=null;privateButtonreduce=null;privateButtonmultiply=null;privateButtondiv
4、ide=null;privateButtonpoint=null;privateButtonnumber0=null;privateButtonnumber1=null;privateButtonnumber2=null;privateButtonnumber3=null;privateButtonnumber4=null;privateButtonnumber5=null;privateButtonnumber6=null;privateButtonnumber7=null;privateButtonnumber8=null;privateButtonnumber9=nu
5、ll;privateButtonclear=null;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);result=(EditText)findViewById(R.id.result);result.setSelection(1);result.setInputType(InputType.TYPE_NULL);equal=(Button)findViewById(R.id.equal
6、);add=(Button)findViewById(R.id.add);reduce=(Button)findViewById(R.id.reduce);multiply=(Button)findViewById(R.id.multiply);divide=(Button)findViewById(R.id.divide);point=(Button)findViewById(R.id.point);clear=(Button)findViewById(R.id.clear);number0=(Button)findViewById(R.id.number0);numbe
7、r1=(Button)findViewById(R.id.number1);number2=(Button)findViewById(R.id.number2);number3=(Button)findViewById(R.id.number3);number4=(Button)findViewById(R.id.number4);number5=(Button)findViewById(R.id.number5);number6=(Button)findViewById(R.id.number6);number7
此文档下载收益归作者所有