如何在 Android activity class 中获得点击?

How to get click on board in an activity class in Android?

我想知道如何创建一个侦听器,当我单击在 Activity class 中设置为 ContentView 的 boardView(扩展视图)时,它会做出反应。代码如下。

public class GameActivity extends Activity {
private SharedPreferences preferences;
private LiftGame game;
private LiftPlayer playerRed;
private LiftPlayer playerBlack;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BoardView boardView = new BoardView(this);
    setContentView(boardView);
    preferences = getSharedPreferences("CONFIG", Activity.MODE_PRIVATE);
    createGame();
}
}    

你试过boardView.setOnClickListener了吗?