Android Question Tabstrip clearing before add panels

ALBRECHT

Active Member
Licensed User
Hello,

I have a pb when i use more times the sub below, that create 3 panels inside a tabstrip which is included inside a ScrollView:

So i would like to clear or delete the tabstrip before creating it again

Without clearing it beforehand, when i use that sub again, i duplicate the 3 tabs but do not replace they !

please, how to do that ?

I have tried multiple functions like removeallviews etc ... but no way

B4X:
Ts.LoadLayout("PanelSV", "DATA")
        ScrollView1.Panel.LoadLayout("ProdPage1")
        ScrollView1.Panel.Height = DHEIGHT * 1.3
        
        Ts.LoadLayout("PanelSV", "IMAGES")
        ScrollView1.Panel.LoadLayout("ProdPage2")
        ScrollView1.Panel.Height = DHEIGHT * 1.3
               
        Ts.LoadLayout("PanelSV", "SEO")
        ScrollView1.Panel.LoadLayout("ProdPage3")
        ScrollView1.Panel.Height = DHEIGHT * 1.3
Thanks
 

Erel

Administrator
Staff member
Licensed User

ALBRECHT

Active Member
Licensed User
hello Erel,
I already found your subs a few days ago but i had some pbs of using it when it becomes from a new layout.
i can t use removeviews because it' a very complicated panel (articles page), which is created with the designer and difficult to add view again

I show you an example with the 2 ways (code bellow) :
- So the first page is load correctly (but could be duplicate as said in my post above)
- the second page with the InsertPage sub : the tab appears but the page inside the tabstrip is empty

there is something that i dont master ...

B4X:
'TabStrip1 is inside "ProdPage" layout
PanelProduct.LoadLayout("ProdPage")

'change Panel
PanelCentral.SendToBack
PanelCentral.Visible = False    
PanelProduct.BringToFront
PanelProduct.Visible = True
 
            
TabStrip1.LoadLayout("ScrollView", "DATA")
ScrollView1.Panel.Height = DHEIGHT * 2
'way 1   
ScrollView1.Panel.LoadLayout("ProdPage1")
'way 2
Tools.InsertPage(TabStrip1, 1, ScrollView1, "DATA")
 
Last edited:

ALBRECHT

Active Member
Licensed User
So, do you have an example of
tabstrip InsertPage and RemovePage sub using with :
- Pages inside layout (bal)
- a tabstrip inside a panel

many thanks
 

ALBRECHT

Active Member
Licensed User
With the removepage and addpage subs :

B4X:
'Return the removed page
Sub RemovePage (ts As TabStrip, Index As Int) As Panel
   If ts.CurrentPage >= Index Then ts.ScrollTo(0, False)
   Dim jo As JavaObject = ts
   Dim p As Panel = jo.GetFieldJO("pages").RunMethod("remove", Array(Index))
jo.GetFieldJO("titles").RunMethod("remove", Array(Index))
   RefreshTabStrip (ts)
   Return p
End Sub
Is it a way to loop with the page number position ? Like

B4X:
For i = 0 to nbtabs
Removepage(ts,i)
Next
Or Insertpage between 2 tabs positions,
or at the begining or at the end ...
(At the end IS probably thé default)

?
 

ALBRECHT

Active Member
Licensed User
ok i have found a solution with :

B4X:
        PanelCentral.Visible = False
        TabStrip1.LoadLayout("ScrollView", "DATA")
        ScrollView1.Panel.Height = DHEIGHT * 2
        ScrollView1.Panel.LoadLayout("ProdPage1")
       
        TabStrip1.LoadLayout("ScrollView", "IMAGES")
        ScrollView1.Panel.Height = DHEIGHT * 2
        ScrollView1.Panel.LoadLayout("ProdPage2")
       
        TabStrip1.LoadLayout("ScrollView", "SEO")
        ScrollView1.Panel.Height = DHEIGHT * 2
        ScrollView1.Panel.LoadLayout("ProdPage3")
       
'clearing the 3 first tabs if i return on that sub ...        
Dim NbTabs As Int = Tools.GetAllTabLabels(TabStrip1).Size
        If NbTabs > 3 Then
            Tools.RemovePage(TabStrip1, 0)
            Tools.RemovePage(TabStrip1, 0)
            Tools.RemovePage(TabStrip1, 0)
        End If
        PanelCentral.Visible = False
GetAllTabLabels :

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

Sub RemovePage(ts As TabStrip, Index As Int) As Panel
    If ts.CurrentPage >= Index Then ts.ScrollTo(0, False)
    Dim jo As JavaObject = ts
    Dim p As Panel = jo.GetFieldJO("pages").RunMethod("remove", Array(Index))
    jo.GetFieldJO("titles").RunMethod("remove", Array(Index))
    RefreshTabStrip (ts)
    Return p
End Sub

Sub RefreshTabStrip(ts As TabStrip)
    Dim jo As JavaObject = ts
    jo.RunMethod("resetAdapter", Null)
    jo.GetFieldJO("vp").RunMethodJO("getAdapter", Null).RunMethod("notifyDataSetChanged", Null)
    jo.GetFieldJO("tabStrip").RunMethod("notifyDataSetChanged", Null)
End Sub
if it could help someone
 
Top