Android Question TabStripviewPager - Error getting current tab text

trueboss323

Active Member
Licensed User
Longtime User
I've been trying to get the name of the current selected tab each time the user switches tabs. But the code below results in a crash:

B4X:
Sub TabStrip1_PageSelected (Position As Int)
    Log(GetCurrentPageTabText(TabStrip1))
End Sub

And this is the way I add my tabs:
B4X:
TabStrip1.LoadLayout("1","First")
TabStrip1.LoadLayout("2","Second")
TabStrip1.LoadLayout("3","Third")
B4X:
Sub GetCurrentPageTabText(tb As TabStrip) As String
   Dim lbl As Label = GetAllTabLabels(tb).Get(tb.CurrentPage)
   Return lbl.Text

End Sub
Public Sub GetAllTabLabels (tabstrip As TabStrip) As List
   Dim jo As JavaObject = tabstrip
   Dim r As Reflector
   r.Target = jo.GetField("tabStrip")
   Dim tc As Panel = r.GetField("tabsContainer")
   Dim resd As List
   resd.Initialize
   For Each v As View In tc
     If v Is Label Then resd.Add(v)
   Next
   Return res

End Sub
 
Last edited:

trueboss323

Active Member
Licensed User
Longtime User
Here's the error:

java.lang.ClassCastException: anywheresoftware.b4a.object.XmlLayoutBuilder cannot be cast to java.util.List
at com.chirco.main._getalltablabels(main.java:6846)
at com.chirco.main._getcurrentpagetabtext(main.java:6886)
at com.chirco.main._tabstrip1_pageselected(main.java:7994)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$1.run(BA.java:293)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
** Activity (main) Pause, UserClosed = true **
 
Last edited:
Upvote 0
Top