This could be something I'm missing about Scala. Admittedly this is an
area I struggle with but I like to think I understand it...

I have this code:

            dialog(getString(R.string.confirmOverwrite)) <~
              positiveYes({
                Log.d("editorcheck", "here")
                setupActivity()
                save(shouldShutDownAfter)
              }) <~
              negativeNo(startFileManager(FileOp.Save)) <~
              speak

This is supposed to present a "file exists: overwrite?" dialog. If the
user clicks Yes, the activity is set up with file contents and a save()
method is called to persist the data to external storage.

Only, when this code runs, not only is the dialog not shown, but I see
the "Here" log message indicating that the positiveYes function is
running even without a click.

My assumption is this is because putting code in {...} runs it directly
rather than treating it as a higher-order function. My usual approach to
this is as follows:

            dialog(getString(R.string.confirmOverwrite)) <~
              positiveYes({ () =>
                Log.d("editorcheck", "here")
                setupActivity()
                save(shouldShutDownAfter)
              }) <~
              negativeNo(startFileManager(FileOp.Save)) <~
              speak

Only, that yields:

[error] C:\Users\nolan\Projects\B2G\Editor\src\main\scala\ui.scala:169:
type mis
match;
[error]  found   : () => Unit
[error]  required: android.content.DialogInterface.OnClickListener
[error]               positiveYes({ () =>
[error]                                ^


The negativeNo code doesn't appear to trigger, perhaps because Scala
treats that as a higher-order function and doesn't execute it.

Am I missing something, or should there be a () => Unit implicit
conversion in Macroid? Do I have to create a function with def for every
piece of code executed in a click listener that is more complex than a
single call to an existing function?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to