2023年12月21日发(作者:新能源)
---功能实现public class MainActivity extends AppCompatActivity implements kListener { Button btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9, btnClear,btnPlus,btnSubtract,btnMultiply,btnDivide,btnSum,btnPoint; TextView text; String str = \"\"; @Override protected void onCreate(Bundle savedInstanceState) { te(savedInstanceState); setContentView(ty_main); btn0 = (Button) findViewById(0); btn1 = (Button) findViewById(1); btn2 = (Button) findViewById(2); btn3 = (Button) findViewById(3); btn4 = (Button) findViewById(4); btn5 = (Button) findViewById(5); btn6 = (Button) findViewById(6); btn7 = (Button) findViewById(7); btn8 = (Button) findViewById(8); btn9 = (Button) findViewById(9); btnClear = (Button) findViewById(ar); btnPlus = (Button) findViewById(s); btnSubtract = (Button) findViewById(tract); btnMultiply = (Button) findViewById(tiply); btnDivide = (Button) findViewById(ide); btnPoint = (Button) findViewById(nt); btnSum = (Button) findViewById(); text = (TextView) findViewById() ; lickListener(this); lickListener(this);
lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(this); lickListener(new click()); //给所有按钮注册点击事件 } @Override public void onClick(View v) { String input=t().toString(); switch (()){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case nt: t(input+((Button)v).getText()); break; case s: case tract: case tiply: case ide: t(input + \" \" + ((Button)v).getText() + \" \"); //给运算符前后加空格,好判断 break; case ar: t(\"\"); break; } } class click implements kListener { public void onClick (View v) { getResult(); } } private void getResult () { String str1 = t().toString(); if(str1 == null || (\"\")){ return; } if(!ns(\" \")){ return ; }
更多推荐
空格,实现,点击,新能源,注册
发布评论