Ad
FindNavController().navigate(direction) Does Not Work For View.OnLongClickListener, But It Works For View.OnClickListener
Android Developer Canary 3.4, kotlin.
Found that View.OnLongClickListener gives a type mismatch. Isn't View.OnLongClickListener not taken into consideration for the new Navigation Graph in Android ?
private fun createOnClickListener(stationId: String): View.OnClickListener
{
return View.OnClickListener {
val direction = StationListFragmentDirections.ActionStationListFragmentToStationDetailFragment(stationId)
it.findNavController().navigate(direction)
}
}
private fun createOnLongClickListener(stationId: String, kindId: String): View.OnLongClickListener
{
return View.OnLongClickListener {
val direction = StationListFragmentDirections.ActionStationListFragmentToUpdatePriceFragment(stationId,kindId)
it.findNavController().navigate(direction) // <--- Gives error here
}
}
The above two functions should behave the same, but the lower (createOnLongClickListener) gives a 'Type mismatch' error for the 'direction'.
Isn't support for navigation added for View.OnLongClickListener ?
Ad
Answer
View.OnLongClickListener need return type as Boolean
Example:
val longClick = View.OnLongClickListener {
[email protected] true
}
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad