当前位置:   article > 正文

用Android Studio制作一个简易的计算器,Android开发经验的有效总结_android studio计算器报告

android studio计算器报告

首先建立按钮(这只是单单的建议按钮,连接按钮的代码在底下)

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

private GridLayout gridlayout;

private EditText edit;

private TextView view;

private Button add;

private Button substact;

private Button multiply;

private Button divide;

private Button seven;

private Button eight;

private Button nine;

private Button left;

private Button four;

private Button five;

private Button six;

private Button right;

private Button three;

private Button two;

private Button one;

private Button Clean;

private Button dot;

private Button zero;

private Button equal;

}

然后把每个按钮和对应的数字符号对应起来

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

gridlayout = (GridLayout) findViewById(R.id.gridlayout);

edit = (EditText) findViewById(R.id.edit);

view = (TextView) findViewById(R.id.view);

add = (Button) findViewById(R.id.add);

substact = (Button) findViewById(R.id.substact);

multiply = (Button) findViewById(R.id.multiply);

divide = (Button) findViewById(R.id.divide);

seven = (Button) findViewById(R.id.seven);

eight = (Button) findViewById(R.id.eight);

nine = (Button) findViewById(R.id.nine);

left = (Button) findViewById(R.id.left);

four = (Button) findViewById(R.id.four);

five = (Button) findViewById(R.id.five);

six = (Button) findViewById(R.id.six);

right = (Button) findViewById(R.id.right);

three = (Button) findViewById(R.id.three);

two = (Button) findViewById(R.id.two);

one = (Button) findViewById(R.id.one);

Clean = (Button) findViewById(R.id.Clean);

dot = (Button) findViewById(R.id.dot);

zero = (Button) findViewById(R.id.zero);

equal = (Button) findViewById(R.id.equal);

edit.setOnClickListener(this);

view.setOnClickListener(this);

add.setOnClickListener(this);

multiply.setOnClickListener(this);

divide.setOnClickListener(this);

dot.setOnClickListener(this);

one.setOnClickListener(this);

two.setOnClickListener(this);

three.setOnClickListener(this);

four.setOnClickListener(this);

five.setOnClickListener(this);

six.setOnClickListener(this);

seven.setOnClickListener(this);

eight.setOnClickListener(this);

nine.setOnClickListener(this);

zero.setOnClickListener(this);

right.setOnClickListener(this);

Clean.setOnClickListener(this);

left.setOnClickListener(this);

equal.setOnClickListener(this);

substact.setOnClick

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/223287
推荐阅读
相关标签
  

闽ICP备14008679号