I'm trying to call Android's TextView.setText(...) method, which seems to take a java.lang.CharSequence (not java.lang.String) as an argument. This CharSequence is apparently (?) an interface implemented by java.lang.String. What should I do to successfully pass a Nim string to TextView.setText(...)?
I tried the following:
when defined android:
import jnim
import android/os/bundle
import android/content/context
import android/view/view
import android/app/activity
jclassDef java.lang.CharSequence of JVMObject
jclass android.widget.TextView of JVMObject:
proc new(c: Context)
proc setText(s: CharSequence)
# ...
proc ...(jenv: JNIEnvPtr; jthis: jobject) {.cdecl, exportc, dynlib.} =
let v = TextView.new(cast[MainActivity](jthis))
v.setText("hello flappy nim")
jthis.setContentView(v)
but I'm getting an error like below:
C:\prog\flappy-nim\src\flappy_nim.nim(44, 8) Error: type mismatch: got <TextView, string>
but expected one of:
proc setText(this: TextView; s: CharSequence)
first type mismatch at position: 2
required type for s: CharSequence
but expression '"hello flappy nim"' is of type: string
1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
expression: setText(v, "hello flappy nim")
I'm trying to call Android's
TextView.setText(...)
method, which seems to take ajava.lang.CharSequence
(notjava.lang.String
) as an argument. ThisCharSequence
is apparently (?) an interface implemented byjava.lang.String
. What should I do to successfully pass a Nim string toTextView.setText(...)
?I tried the following:
but I'm getting an error like below:
Any ideas or thoughts?