Android Question Nine patch & B4X

Jerryk

Member
Is there an option to apply Nine patch on B4X elements? Specifically on B4XFloatTextField? I want to hide that line at the bottom of the edit field.
 

Jerryk

Member
B4X:
Private eWord As B4XFloatTextField
    ...
    
SetNinePatchDrawable(eWord, "grey")
    ...
    
Sub SetNinePatchDrawable(Control As View, ImageName As String)
    Dim r As Reflector
    Dim package As String
    Dim id As Int
    package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
    id = r.GetStaticField(package & ".R$drawable", ImageName)
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub

crashed on line: Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")

Error occurred on line: 77 (pEdit)
java.lang.ClassCastException: cz.flashcards3.b4xfloattextfield cannot be cast to android.view.View
at anywheresoftware.b4a.objects.ViewWrapper.setBackground(ViewWrapper.java:105)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at cz.flashcards3.pedit._b4xpage_created(pedit.java:67)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1057)
...

 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
B4X:
Private eWord As B4XFloatTextField
    ...
    
SetNinePatchDrawable(eWord, "grey")
    ...
    
Sub SetNinePatchDrawable(Control As View, ImageName As String)
    Dim r As Reflector
    Dim package As String
    Dim id As Int
    package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
    id = r.GetStaticField(package & ".R$drawable", ImageName)
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub

crashed on line: Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")

Error occurred on line: 77 (pEdit)
java.lang.ClassCastException: cz.flashcards3.b4xfloattextfield cannot be cast to android.view.View
at anywheresoftware.b4a.objects.ViewWrapper.setBackground(ViewWrapper.java:105)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at cz.flashcards3.pedit._b4xpage_created(pedit.java:67)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1057)
...

Try
SetNinePatchDrawable(eWord.TextField, "grey")
 
Upvote 0
Top