通过在 android 中使用多个按钮来执行单个操作,例如按下 button1 和 button2,我们会得到一个操作。解决这个问题的最佳方法是什么
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.braill);
Button btn1 = (Button) findViewById(R.id.btn1);
Button btn2 = (Button) findViewById(R.id.btn2);
Button btn3 = (Button) findViewById(R.id.btn3);
Button btn4 = (Button) findViewById(R.id.btn4);
Button btn5 = (Button) findViewById(R.id.btn5);
Button btn6 = (Button) findViewById(R.id.btn6);
Button complete = (Button) findViewById(R.id.complete);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
btn4.setOnClickListener(this);
btn5.setOnClickListener(this);
btn6.setOnClickListener(this);
complete.setOnClickListener(this);
}
@Override
public void onClick(View v) {
final EditText edittext = (EditText) findViewById(R.id.edtext);
switch(v.getId()){
case R.id.btn1 & R.id.btn2 & R.id.complete:
{
Toast toast = Toast.makeText(getApplicationContext(), "Button 1", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0, 0);
toast.show();
edittext.append("a");
break;
}
}
}}