Android Question [SOLVED]Try to use TabStripViewPagerExtendet?

nanjidusan

Member
Licensed User
When I use SetTabLeft(tabstrip As TabStrip,left As Int,Position As Int)
B4X:
panel.Initialize("")
    Activity.AddView(panel,0,0,100%x,90%y)
    panel.LoadLayout("tabstrip")
    tabstrip1.LoadLayout("shengmu","page1")
    tabstrip1.LoadLayout("yunmu","page2")
    tabstrip1.LoadLayout("shengdiao","page3")
    panel.Visible=False
    tabstripview.SetTabLeft(tabstrip1,20dip,tabstrip1.CurrentPage)

throws this:
B4X:
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
Panel size is unknown. Layout may not be loaded correctly.
Error occurred on line: 200 (tabstripview)
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams
    at anywheresoftware.b4a.objects.ViewWrapper.setLeft(ViewWrapper.java:182)
    at dh.apk.tabstripview._settableft(tabstripview.java:79)
    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: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 java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at dh.apk.main.afterFirstLayout(main.java:104)

How to solve this problem?
 

nanjidusan

Member
Licensed User
B4X:
Public Sub SetTabLeft(tabstrip As TabStrip,left As Int,Position As Int)
    
    Dim i As Int
    For Each lbl As Label In GetAllTabLabels(tabstrip)
        If i = Position Then
            
            lbl.Left = left

        End If
        i = i + 1
    Next
    
End Sub
 
Upvote 0

nanjidusan

Member
Licensed User
You shouldn't see this warning: Panel size is unknown. Layout may not be loaded correctly.

It means that the layout will not work properly.

What is SetTabLeft supposed to do?

Thanks.
B4X:
panel.Initialize("panel")
Activity.AddView(panel,0,0,100%x,90%y)
panel.LoadLayout("tabstrip")
tabstrip1.LoadLayout("shengmu","page1")
tabstrip1.LoadLayout("yunmu","page2")
tabstrip1.LoadLayout("shengdiao","page3")
tabstripview.SetTabLeft(tabstrip1,20dip,tabstrip1.CurrentPage)
It hasn't a warning about panel size
B4X:
** Activity (main) Create, isFirst = true **
Error occurred on line: 200 (tabstripview)
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams
    at anywheresoftware.b4a.objects.ViewWrapper.setLeft(ViewWrapper.java:182)
    at dh.apk.tabstripview._settableft(tabstripview.java:79)
    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:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)

I guess that's not the problem. when use SetTabHeight(tabstrip As TabStrip,height As Int,Position As Int),it works well.
 
Upvote 0

nanjidusan

Member
Licensed User
I want to center the label like this
tab.png
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
or this:
B4X:
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 res As List
    res.Initialize
    For Each v As View In tc
        If v Is Label Then res.Add(v)
    Next
    Return res
 
End Sub

For Each lbl As Label In Main.fun.GetAllTabLabels(ts_main)
        lbl.Width = Round(Activity.Width/3)
    Next
 
Upvote 0

nanjidusan

Member
Licensed User
or this:
B4X:
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 res As List
    res.Initialize
    For Each v As View In tc
        If v Is Label Then res.Add(v)
    Next
    Return res
 
End Sub

For Each lbl As Label In Main.fun.GetAllTabLabels(ts_main)
        lbl.Width = Round(Activity.Width/3)
    Next
Thanks a lot! But it's full, not in the center as I thought.
 
Upvote 0
Top