T trueboss323 Active Member Licensed User Longtime User Sep 4, 2016 #1 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: Code: Copy Sub TabStrip1_PageSelected (Position As Int) Log(GetCurrentPageTabText(TabStrip1)) End Sub And this is the way I add my tabs: Code: Copy TabStrip1.LoadLayout("1","First") TabStrip1.LoadLayout("2","Second") TabStrip1.LoadLayout("3","Third") Code: Copy 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: Sep 5, 2016
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: Code: Copy Sub TabStrip1_PageSelected (Position As Int) Log(GetCurrentPageTabText(TabStrip1)) End Sub And this is the way I add my tabs: Code: Copy TabStrip1.LoadLayout("1","First") TabStrip1.LoadLayout("2","Second") TabStrip1.LoadLayout("3","Third") Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Sep 5, 2016 #2 Can you post the error message from the logs (right click to copy)? Upvote 0
T trueboss323 Active Member Licensed User Longtime User Sep 5, 2016 #3 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 ** Click to expand... Last edited: Sep 5, 2016 Upvote 0
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 ** Click to expand...
Erel B4X founder Staff member Licensed User Longtime User Sep 6, 2016 #4 It should be: Return resd Upvote 0