赞
踩
首先建立按钮(这只是单单的建议按钮,连接按钮的代码在底下)
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。