@Yano
2016-01-03T16:53:41.000000Z
字数 757
阅读 1905
Android
Activity 实现 android.view.View.OnClickListener。
public class MainActivity extends Activity implements
android.view.View.OnClickListener {
private Button button1, button2, button3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
System.out.println("button1");
break;
case R.id.button2:
System.out.println("button2");
break;
case R.id.button3:
System.out.println("button3");
break;
}
}
}