Issue
Could someone please explain, the difference between
actionButton.setOnClickListener{Navigation.createNavigateOnClickListener(R.id.next_action,null)}
and
actionButton.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.next_action,null))
I know first one is a lambda expression. But it does not work (no action on button clicking), second one works.
Thank you very much!
Solution
The first one isn't going to work. The setOnClickListener takes a OnClickListener. You can pass in a lambda for that. Howerver Navigation.createNavigateOnClickListener returns an OnClickListener. So calling it in a lambda would do nothing- it would create a OnClickListener when the button is touched and then throw it away doing nothing with it.
The second one takes the OnClickListener created by the Navigation call and passes it to setOnClickListener. So when the button is clicked, that OnClickListener is called. Which is what you want.
Answered By - Gabe Sechan
Answer Checked By - Robin (JavaFixing Admin)