Android Question Tabstrip clearing before add panels

Discussion in 'Android Questions' started by ALBRECHT, Sep 11, 2019.

  1. ALBRECHT

    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

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. ALBRECHT

    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 ...

    Code:
    '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: Sep 12, 2019
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is difficult to understand what you are doing from these code snippets. You can always put the TabStripViewPager inside a panel. This will allow you to remove the panel and then add a new panel with a new TabStrip.
     
  5. ALBRECHT

    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    No. However I don't see anything special about putting the TabStrip in a panel.

    You also don't need to use RemovePage in that case as you can just remove the complete TabStrip.
     
  7. ALBRECHT

    ALBRECHT Active Member Licensed User

    With the removepage and addpage subs :

    Code:
    'Return the removed page
    Sub RemovePage (ts As TabStrip, Index As Int) As Panel
       
    If ts.CurrentPage >= Index Then ts.ScrollTo(0False)
       
    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

    Code:
    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)

    ?
     
  8. ALBRECHT

    ALBRECHT Active Member Licensed User

    ok i have found a solution with :

    Code:
    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 :

    Code:
    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(0False)
        
    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
     
    José J. Aguilar likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice