0

package com

import android.content.Intent import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.annotation.RequiresApi import com.example.sendit.MainActivity import com.example.sendit.R import kotlinx.android.synthetic.main.activity_sign_in.*

class SignInActivity : AppCompatActivity() { @RequiresApi(Build.VERSION_CODES.M) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_sign_in) btnSignUp.setOnContextClickListener { val intent = Intent(this,MainActivity::class.java) startActivity(intent)}

btnLogin.setOnContextClickListener { val regIntent = Intent(this,Log_inActivity::class.java) startActivity(regIntent) } 

} }

1 Answer 1

0

Definition of OnContextClickListener:

/** * Interface definition for a callback to be invoked when a view is context clicked. */ public interface OnContextClickListener { /** * Called when a view is context clicked. * * @param v The view that has been context clicked. * @return true if the callback consumed the context click, false otherwise. */ boolean onContextClick(View v); } 

The method onContextClick must return boolean value by signature. In your code snippet last line of lambda passed to setOnContextClickListener returns Unit type because startActivity return void by declaration. That's why just return true (lambda in kotlin uses value retuned by last instruction as return value when her return type not a Unit or void in java terms):

btnLogin.setOnContextClickListener { val regIntent = Intent(this,Log_inActivity::class.java) startActivity(regIntent) true } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.