当前位置: 编程技术>移动开发
Android中button实现onclicklistener事件的两种方式
来源: 互联网 发布时间:2014-10-14
本文导语: 代码如下: package com.demos; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class GetScreenActivity extends Activity { private Button firstBtn = null; private Button secBtn = null;...
代码如下:
package com.demos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class GetScreenActivity extends Activity {
private Button firstBtn = null;
private Button secBtn = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
firstBtn = (Button) findViewById(R.id.firstBtn);
secBtn = (Button) findViewById(R.id.secBtn);
firstBtn.setOnClickListener(listener);
secBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
private OnClickListener listener = new OnClickListener(){
@Override
public void onClick(View view) {
}
};
}