Android Question Change the text of every RadioButton

Toley

Active Member
Licensed User
Longtime User
I want to change the text of many radio buttons in a sub. I did something like that:

B4X:
    For Each r As RadioButton In Activity
        If r.Text.EndsWith("s1") Then
            r.Text = all_text.Get(26) & " 1"
        End If
    Next
Note that all_text is a list read from a file. It works correctly.

It compile normally but I receive this error when I run it:

B4X:
Copying updated assets files (5)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 2312 (Main)
java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to android.widget.TextView
    at anywheresoftware.b4a.objects.TextViewWrapper.getText(TextViewWrapper.java:36)
    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:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at st.st.dermafusion.main._init_config_file(main.java:890)
    at st.st.dermafusion.main._activity_create(main.java:829)
    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:157)
    at st.st.dermafusion.main.afterFirstLayout(main.java:105)
    at st.st.dermafusion.main.access$000(main.java:17)
    at st.st.dermafusion.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Looks like the text cannot be retrieve from a RadioButton that way. Any other suggestion?
 
Solution
Try something like this . . .

B4X:
Sub Button1_Click
    For Each v As B4XView In Activity.GetAllViewsRecursive
        If (v Is RadioButton) Then v.text = v.text & " !"
    Next
End Sub

It works for me.
Top