方法一:
OnClickListener button_listener = new Button.OnClickListener(){
public void onClick(View v){
setTitle("哎呀,button被点了一下");
}
};
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(button_listener);
方法二:
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
setTitle("哎呀,button被点了一下");
}
});
方法三:
public class XXXActivity extends Activity implements Button.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
public void onClick(View v) {
setTitle("哎呀,button被点了一下");
}
}
阅读(2994) | 评论(0) | 转发(0) |