May 29, 2021 Replies: 5 Ok, Good morning to all. It's a small tiny snippet that frustrated me for many years and VOILA today morning I found, so simply the solution that was so simple and silly. So, decided to share to rescue developers' lives. To justify text within the label just use the Reflector library and one line of code: [ReflectorObject].Target = [LabelView] [ReflectorObject].RunMethod2("setJustificationMode", 1, "java.lang.int") That's it. So silly not? Click to expand...
Ok, Good morning to all. It's a small tiny snippet that frustrated me for many years and VOILA today morning I found, so simply the solution that was so simple and silly. So, decided to share to rescue developers' lives. To justify text within the label just use the Reflector library and one line of code: [ReflectorObject].Target = [LabelView] [ReflectorObject].RunMethod2("setJustificationMode", 1, "java.lang.int") That's it. So silly not?
mcqueccu Expert Licensed User Longtime User May 29, 2021 #2 Thank you for the snippet. Use code tags to post codes B4X: Copy [ReflectorObject].Target = [LabelView] [ReflectorObject].RunMethod2("setJustificationMode", 1, "java.lang.int")
Thank you for the snippet. Use code tags to post codes B4X: Copy [ReflectorObject].Target = [LabelView] [ReflectorObject].RunMethod2("setJustificationMode", 1, "java.lang.int")
yiankos1 Well-Known Member Licensed User Longtime User Jun 29, 2021 #3 Hello, I am trying your snippet but throws error: B4X: Copy Error occurred on line: 138 (fullArticle) java.lang.NoSuchMethodException: setJustificationMode [int] at java.lang.Class.getMethod(Class.java:1981) at java.lang.Class.getDeclaredMethod(Class.java:1960) at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214) at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817) at com.dreamon.therapy.fullarticle._clvarticles_visiblerangechanged(fullarticle.java:451) 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:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.BA$2.run(BA.java:387) at android.os.Handler.handleCallback(Handler.java:761) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6577) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) B4X: Copy Private rf As Reflector rf.Target=lblMainDummy rf.RunMethod2("setJustificationMode", 1, "java.lang.int")
Hello, I am trying your snippet but throws error: B4X: Copy Error occurred on line: 138 (fullArticle) java.lang.NoSuchMethodException: setJustificationMode [int] at java.lang.Class.getMethod(Class.java:1981) at java.lang.Class.getDeclaredMethod(Class.java:1960) at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214) at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817) at com.dreamon.therapy.fullarticle._clvarticles_visiblerangechanged(fullarticle.java:451) 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:351) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144) at anywheresoftware.b4a.BA$2.run(BA.java:387) at android.os.Handler.handleCallback(Handler.java:761) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6577) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831) B4X: Copy Private rf As Reflector rf.Target=lblMainDummy rf.RunMethod2("setJustificationMode", 1, "java.lang.int")
klaus Expert Licensed User Longtime User Jun 29, 2021 #4 You can also do it with the JavaObject library: B4X: Copy Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1))
You can also do it with the JavaObject library: B4X: Copy Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1))
yiankos1 Well-Known Member Licensed User Longtime User Jul 1, 2021 #5 klaus said: You can also do it with the JavaObject library: B4X: Copy Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1)) Click to expand... Goodmorning Klaus, Thank you for your time adding your solution. I don't know why throws this error again. My label(textView) does not have this method (setJustificationMode) and i can't figure out why. By the way it would pretty for my app to have this justification but i will try to live without it! Greetings from extra HOT Greece. (40 °C at 01:00 p.m.)
klaus said: You can also do it with the JavaObject library: B4X: Copy Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1)) Click to expand... Goodmorning Klaus, Thank you for your time adding your solution. I don't know why throws this error again. My label(textView) does not have this method (setJustificationMode) and i can't figure out why. By the way it would pretty for my app to have this justification but i will try to live without it! Greetings from extra HOT Greece. (40 °C at 01:00 p.m.)
mcqueccu Expert Licensed User Longtime User Jul 1, 2021 #6 yiankos1 said: Goodmorning Klaus, Thank you for your time adding your solution. I don't know why throws this error again. My label(textView) does not have this method (setJustificationMode) and i can't figure out why. By the way it would pretty for my app to have this justification but i will try to live without it! Greetings from extra HOT Greece. (40 °C at 01:00 p.m.) Click to expand... Which android version are you testing it on? If its less than android 8 (api 26) it will not work, because it was introduced from API level 26. Try this (It means the justification will only happen on android 8+ devices only B4X: Copy Dim p As Phone '<----Add phone Library If p.SdkVersion >= 26 Then Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1)) End If
yiankos1 said: Goodmorning Klaus, Thank you for your time adding your solution. I don't know why throws this error again. My label(textView) does not have this method (setJustificationMode) and i can't figure out why. By the way it would pretty for my app to have this justification but i will try to live without it! Greetings from extra HOT Greece. (40 °C at 01:00 p.m.) Click to expand... Which android version are you testing it on? If its less than android 8 (api 26) it will not work, because it was introduced from API level 26. Try this (It means the justification will only happen on android 8+ devices only B4X: Copy Dim p As Phone '<----Add phone Library If p.SdkVersion >= 26 Then Private jo As JavaObject = Label1 jo.RunMethod("setJustificationMode", Array As Object(1)) End If