android简单计算器代码.docx
《android简单计算器代码.docx》由会员分享,可在线阅读,更多相关《android简单计算器代码.docx(11页珍藏版)》请在冰豆网上搜索。
android简单计算器代码
packageclassCalculatordemoActivityextendsActivityimplementsOnClickListener{
/**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){
(savedInstanceState);
add=(Button)findViewByIdsub=(Button)findViewByIdmult=(Button)findViewByIddiv=(Button)findViewByIdequ=(Button)findViewByIdbut1=(Button)findViewByIdbut3=(Button)findViewByIdbut2=(Button)findViewByIdbut4=(Button)findViewByIdbut5=(Button)findViewByIdbut6=(Button)findViewByIdbut7=(Button)findViewByIdbut8=(Button)findViewByIdbut9=(Button)findViewByIdbut0=(Button)findViewByIddim=(Button)findViewByIdetext=(EditText)findViewById(newAListener());
(newAListener());
<
(newAListener());
(newAListener());
(newListener());
(this);
(this);
(this);
(this);
(this);
(this);
"
(this);
(this);
(this);
(this);
(this);
}
@Override
publicvoidonClick(Viewv){
oString();
…
if("")){
}else{
doubled=(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;
}
}
("");
if(add)){
sign="+";
}
if(div)){
sign="/";
-
}
if(mult)){
sign="*";
}
if(sub)){
sign="-";
}
tem="";
}
】
}
classListenerimplementsOnClickListener{
@Override
publicvoidonClick(Viewarg){
oString();
if("")){
}else{
doubled=(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;
}
}
.
(value+"");
sign="a";
value=0;
tem="";
}
}
}
android=""
)
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
orientation="vertical">
android:
id="@+id/etext"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
layout_margin="5px">
—