Sucho
Sucho

Reputation: 321

Use of setOnClickListener()

I am very new to Android app development, so will ask a very basic question. What is the work of setOnClickListener()?

In the following code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_sudoku);

    View continueButton = findViewById(R.id.continue_button);
    continueButton.setOnClickListener(this);
    View newButton = findViewById(R.id.new_button);
    newButton.setOnClickListener(this);
    View aboutButton = findViewById(R.id.about_button);
    aboutButton.setOnClickListener(this);
    View exitButton = findViewById(R.id.exit_button);
    exitButton.setOnClickListener(this);
}`

What is the function of aboutButton.setOnClickListener(this)?

Upvotes: 0

Views: 79

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

setOnClickListener() indicates that the supplied OnClickListener should be called with onClick() when the view is clicked.

In this case, the OnClickListener is the Activity itself. OnClickListener is an interface which this Activity implements.

Upvotes: 3

Related Questions