android="
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
orientation="vertical">
android:
id="@+id/tableLayout1"
android:
layout_width="match_parent"
android:
layout_height="wrap_content"
android:
collapseColumns="4">
android:
id="@+id/tableRow_et"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/et"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
layout_span="4"
android:
focusable="false"
android:
gravity="right"
android:
inputType="text"
android:
singleLine="true">
android:
id="@+id/tableRow1"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/tableRow2"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/bt_4"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="4"/>
android:
id="@+id/bt_5"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="5"/>
android:
id="@+id/bt_6"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="6"/>
android:
id="@+id/bt_divide"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="/"/>
android:
id="@+id/tableRow3"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/bt_1"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="1"/>
android:
id="@+id/bt_2"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="2"/>
android:
id="@+id/bt_3"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="3"/>
android:
id="@+id/bt_multiply"
android:
layout_width="80px"
android:
layout_height="80px"
android:
text="*"/>
android:
id="@+id/tableRow4"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/bt_0"
android:
layout_width="50px"
android:
layout_height="80px"
android:
text="0"/>
android:
id="@+id/bt_point"
android:
layout_width="50px"
android:
layout_height="80px"
android:
text="."/>
android:
id="@+id/bt_add"
android:
layout_width="50px"
android:
layout_height="80px"
android:
text="+"/>
android:
id="@+id/bt_sub"
android:
layout_width="50px"
android:
layout_height="80px"
android:
text="-"/>
android:
id="@+id/tableRow4"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/bt_equal"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
android:
layout_span="3"
android:
text="="/>
android:
id="@+id/bt_clear"
android:
layout_width="50px"
android:
layout_height="80px"
android:
text="clear"/>
(二)、.java功能代码
packageweibo.test.ui;
importjava.util.ArrayList;
importjava.util.List;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
importweibo.lixiaodaoaaa.ui.R;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.content.pm.PackageManager;
importandroid.os.Bundle;
importandroid.view.KeyEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ListView;
importcom.zsy.flipper.AppInfUtil;
importcom.zsy.flipper.AppInfo;
publicclassfffActivityextendsActivity
{
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.activity_fff);
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");
bt_0.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("0");
et_play.setText(str_display.toString());
}
});
bt_1.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("1");
et_play.setText(str_display.toString());
}
});
bt_2.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("2");
et_play.setText(str_display.toString());
}
});
bt_3.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("3");
et_play.setText(str_display.toString());
}
});
bt_4.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("4");
et_play.setText(str_display.toString());
}
});
bt_5.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("5");
et_play.setText(str_display.toString());
}
});
bt_6.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("6");
et_play.setText(str_display.toString());
}
});
bt_7.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("7");
et_play.setText(str_display.toString());
}
});
bt_8.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("8");
et_play.setText(str_display.toString());
}
});
bt_9.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_display.append("9");
et_play.setText(str_display.toString());
}
});
bt_point.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
if(flag)
{
str_display.append(".");
flag=false;
}
}
});
bt_back.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
if(str_display.length()!
=0)
{
str_display.deleteCharAt(str_display.length()-1);
et_play.setText(str_display.toString());
}
}
});
bt_add.setOnClickListener(newOnClickListener()
{
@Override
publicvoidonClick(Viewv)
{
str_oper="+";
if(!
(str_display.toString()==""))
{
num1+=Double.parseDouble(str_display.toString());
str_display=newStringBuffer("");
}
if(!
(str_result==null))
{