【发布时间】:2010-12-03 00:20:24
【问题描述】:
假设我在 LinearLayout 中有几个按钮,其中 2 个是:
mycards_button = ((Button)this.findViewById(R.id.Button_MyCards));
exit_button = ((Button)this.findViewById(R.id.Button_Exit));
我在他们两个上都注册了setOnClickListener():
mycards_button.setOnClickListener(this);
exit_button.setOnClickListener(this);
如何制作 SWITCH 以区分 Onclick 中的两个按钮?
public void onClick(View v) {
switch(?????){
case ???:
/** Start a new Activity MyCards.java */
Intent intent = new Intent(this, MyCards.class);
this.startActivity(intent);
break;
case ???:
/** AlerDialog when click on Exit */
MyAlertDialog();
break;
}
【问题讨论】:
-
我不喜欢为此使用菜单,因为我可以将按钮放在布局上我想要的任何位置......