code: private void setupButtons() {
          cancelButton = (TextView) findViewById(R.id.cancelButton);
          cancelButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  setResult(CANCELLED);
                  finish();
              }
          });
          forgetButton = (TextView) findViewById(R.id.forgotPin);
          forgetButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onForgotPin();
                  setResult(FORGOT);
                  finish();
              }
          });
      }
docs: Setting up cancel and forgot buttons and adding onClickListeners to them