package xixi.dx;
import android.R.integer;
import android.R.string;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class CounterMain extends Activity {
/** Called when the activity is first created. */
private EditText txtContent;
private Button btn0;
private Button btn1;
private Button btn2;
private Button btn3;
private Button btn4;
private Button btn5;
private Button btn6;
private Button btn7;
private Button btn8;
private Button btn9;
private Button btnSin;
private Button btnCos;
private Button btn2x;
private Button btnx2;
private Button btnXY;
private Button btnClear;
private Button btnAdd;
private Button btnCut;
private Button btnRide;
private Button btnDivide;
private Button btndian;
private Button btnWorth;
private String num1="";
private String num2="";
private String allString="";
private int signString=0;
private Double endNum=0.0;
private boolean two=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* btn0=(Button)findViewById(R.id.btn0);
btn1=(Button)findViewById(R.id.btn1);
btn2=(Button)findViewById(R.id.btn2);
btn3=(Button)findViewById(R.id.btn3);
btn4=(Button)findViewById(R.id.btn4);
btn5=(Button)findViewById(R.id.btn5);
btn6=(Button)findViewById(R.id.btn6);
btn7=(Button)findViewById(R.id.btn7);
btn8=(Button)findViewById(R.id.btn8);
btn9=(Button)findViewById(R.id.btn9);
btnSin=(Button)findViewById(R.id.btnMS);
btnCos=(Button)findViewById(R.id.btnMC);
btn2x=(Button)findViewById(R.id.btnET);
btnx2=(Button)findViewById(R.id.btnXX);
btnXY=(Button)findViewById(R.id.btnXY);
btnAdd=(Button)findViewById(R.id.btnAdd);
btnCut=(Button)findViewById(R.id.btnCut);
btnRide=(Button)findViewById(R.id.btnRide);
btnDivide=(Button)findViewById(R.id.btnDivide);
btndian=(Button)findViewById(R.id.btndian);
btnWorth=(Button)findViewById(R.id.btnWorth);*/
txtContent=(EditText)findViewById(R.id.txtContent);
txtContent.setTextColor(Color.WHITE);
Button[] buttons=new Button[]{
btn0=(Button)findViewById(R.id.btn0),
btn1=(Button)findViewById(R.id.btn1),
btn2=(Button)findViewById(R.id.btn2),
btn3=(Button)findViewById(R.id.btn3),
btn4=(Button)findViewById(R.id.btn4),
btn5=(Button)findViewById(R.id.btn5),
btn6=(Button)findViewById(R.id.btn6),
btn7=(Button)findViewById(R.id.btn7),
btn8=(Button)findViewById(R.id.btn8),
btn9=(Button)findViewById(R.id.btn9),
btnSin=(Button)findViewById(R.id.btnMS),
btnCos=(Button)findViewById(R.id.btnMC),
btn2x=(Button)findViewById(R.id.btnET),
btnx2=(Button)findViewById(R.id.btnXX),
btnXY=(Button)findViewById(R.id.btnXY),
btnClear=(Button)findViewById(R.id.btnClear),
btnAdd=(Button)findViewById(R.id.btnAdd),
btnCut=(Button)findViewById(R.id.btnCut),
btnRide=(Button)findViewById(R.id.btnRide),
btnDivide=(Button)findViewById(R.id.btnDivide),
btndian=(Button)findViewById(R.id.btndian),
btnWorth=(Button)findViewById(R.id.btnWorth)
};
for(Button btn : buttons)
{
btn.setOnClickListener(new OnClick());
}
}
class OnClick implements OnClickListener
{
@Override
public void onClick(View v) {
/*if(v.getId()==R.id.btn7)
{
Toast.makeText(CounterMain.this, String.valueOf("sdfsdf"), 1000).show();
}
else
{
Toast.makeText(CounterMain.this, String.valueOf(R.id.btn7), 1000).show();
}
}*/
/*try
{
switch (v.getId()) {
case R.id.btn7:
Toast.makeText(CounterMain.this, String.valueOf(R.id.btn7), 1000).show();
break;
default:
Toast.makeText(CounterMain.this, "sfsdfasfd", 1000).show();
break;
}
}
catch (Exception e) {
Toast.makeText(CounterMain.this,"ok", 1000).show();
}*/
switch (v.getId()) {
case R.id.btn0:
if(!two)
{
num1+=0;
allString+=0;
txtContent.setText(allString);
}
else {
num2+=0;
allString+=0;
txtContent.setText(allString);
}
break;
case R.id.btn1:
if(!two)
{
num1+=1;
allString+=1;
txtContent.setText(allString);
}
else {
num2+=1;
allString+=1;
txtContent.setText(allString);
}
break;
case R.id.btn2:
if(!two)
{
num1+=2;
allString+=2;
txtContent.setText(allString);
}
else {
num2+=2;
allString+=2;
txtContent.setText(allString);
}
break;
case R.id.btn3:
if(!two)
{
num1+=3;
allString+=3;
txtContent.setText(allString);
}
else {
num2+=3;
allString+=3;
txtContent.setText(allString);
}
break;
case R.id.btn4:
if(!two)
{
num1+=4;
allString+=4;
txtContent.setText(allString);
}
else {
num2+=4;
allString+=4;
txtContent.setText(allString);
}
break;
case R.id.btn5:
if(!two)
{
num1+=5;
allString+=5;
txtContent.setText(allString);
}
else {
num2+=5;
allString+=5;
txtContent.setText(allString);
}
break;
case R.id.btn6:
if(!two)
{
num1+=6;
allString+=6;
txtContent.setText(allString);
}
else {
num2+=6;
allString+=6;
txtContent.setText(allString);
}
break;
case R.id.btn7:
if(!two)
{
num1+="7";
allString+=7;
txtContent.setText(allString);
}
else {
num2+="7";
allString+=7;
txtContent.setText(allString);
}
break;
case R.id.btn8:
if(!two)
{
num1+=8;
allString+=8;
txtContent.setText(allString);
}
else {
num2+=8;
allString+=8;
txtContent.setText(allString);
}
break;
case R.id.btn9:
if(!two)
{
num1+=9;
allString+=9;
txtContent.setText(allString);
}
else {
num2+=9;
allString+=9;
txtContent.setText(allString);
}
break;
case R.id.btnMS:
if(!two)
{
endNum= Math.sin(Double.valueOf(num1));
allString+="\n 正弦 \n";
txtContent.setText(allString);
two=true;
}
break;
case R.id.btnMC:
if(!two)
{
endNum=Math.cos(Double.valueOf(num1));
allString+="\n 余弦 \n";
txtContent.setText(allString);
two=true;
}
break;
case R.id.btnBack:
Toast.makeText(CounterMain.this, "你好!此功能暂为开发!!", 500).show();
break;
case R.id.btnClear:
num1="";
num2="";
two=false;
allString="";
txtContent.setText(allString);
break;
case R.id.btnXX:
if(!two)
{
endNum=Double.valueOf(num1)*Double.valueOf(num1);
allString+="\n平方";
two=true;
txtContent.setText(allString);
}
break;
case R.id.btnET:
if(!two)
{
endNum=Math.sqrt(Double.valueOf(num1));
allString+="\n开方";
two=true;
txtContent.setText(allString);
}
break;
case R.id.btnXY:
if(!two)
{
signString=1;
allString+="\n次方";
two=true;
txtContent.setText(allString);
}
break;
case R.id.btndian:
if(!two)
{
num1+=".";
allString+=".";
txtContent.setText(allString);
}
else {
num2+=".";
allString+=".";
txtContent.setText(allString);
}
break;
case R
- 1
- 2
- 3
前往页