Reputation: 25
In java, the following code will be used to setup override in My Location Button.
//add location button click listener
map.setOnMyLocationButtonClickListener(new
GoogleMap.OnMyLocationButtonClickListener(){
@Override
public boolean onMyLocationButtonClick()
{
//TODO: Any custom actions
return false;
}
});
However, in kotlin, I can't find any tutorial to learn how to setup the new action in kotlin. I have seen some tutorial on translating java code into kotlin. However, it is not successful.
map.setOnMyLocationButtonClickListener( {
GoogleMap.OnMyLocationButtonClickListener() {
override fun onMyLocationButtonClick() : Boolean {
//TODO: Any custom actions
return false;
}
}
)}
It shows
Type Mismatch. Required: Boolean Found: GoogleMap.OnMyLocationButtonClickListener Expected value of type Boolean
I expected this override is worked but I can't find any tutorial about this. Can anyone solve my problem? Thank you.
Upvotes: 1
Views: 847
Reputation: 351
try
map.setOnMyLocationButtonClickListener(object :
GoogleMap.OnMyLocationButtonClickListener {
override fun onMyLocationButtonClick(): Boolean {
return false
}
})
Upvotes: 0
Reputation: 8422
You can just write. Kotlin supports Java SAM interfaces
map.setOnMyLocationButtonClickListener {
// todo
false
}
Upvotes: 1