哪一种是在 Android 中实现 OnClickListener 接口的最佳方法。
/*- 第一的 - */
public class EmployeeActivity extends Activity implements OnClickListener
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnUpdate = (Button)findViewById(R.id.btnUpdate);
Button btnEdit = (Button)findViewById(R.id.btnEdit);
btnUpdate.setOnClickListener(this);
btnEdit.setOnClickListener(this);
@Override
public void onClick(View v) {
if (v == btnAddEmployee)
{}
if (v == btnUpdate)
{}
}
/ - 第二 - /
public class EmployeeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnUpdate = (Button)findViewById(R.id.btnUpdate);
Button btnEdit = (Button)findViewById(R.id.btnEdit);
btnUpdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
btnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}