Android Question Delete tabs from TabStrip

Hello everyone!

I am building an Android App with B4X for a scanner. In the module, that I'm writing at this moment i want to present some pieces of info about the product scanned to the user. To do that i use TabStrip (because in some cases i need 2 pages for the info and because i like the way it opens the new page and slides). What i need is to close the tabs, every time i scan a new item (TextChanged Event), but i cant find a solution.

Here is my code:

text change - create tabs:
Private Sub ScanHereMC_TextChanged (Old As String, New As String)

'  I want the existing tabs to be deleted here (if any)

    Dim prefix As String
    
    If New.StartsWith("02") Then
        prefix = "02"
    Else If New.StartsWith("91") Then
        prefix = "91"
    End If
    
    Dim j As HttpJob
    j.Initialize("", Me)
    Dim link As String = "The API link here"
    
    Try
        Dim url As String = Main.ini.Get("URL")
        j.Download(url & link & prefix & "/" & New )
        j.GetRequest.SetHeader("Authorization", "Bearer " & token)
        wait for (j) jobdone (j As HttpJob)
        If j.Success Then
            
            Dim parser As JSONParser
            parser.Initialize(j.GetString)
            Dim jRoot As List = parser.NextArray
            Dim jmap As Map = jRoot.Get(0).As(Map)
            If prefix  = "02" Then
            
'                Two tabs from two Lay files
                InfoScroll.LoadLayout("Lay_InfoScroll", "Βασικές Πληροφορίες")
                InfoScroll.LoadLayout("Lay_InfoTable", "Ανά Θέση")
                
                InfoTable.AddColumn("ΘΕΣΗ", InfoTable.COLUMN_TYPE_TEXT)
                InfoTable.AddColumn("STATUS", InfoTable.COLUMN_TYPE_TEXT)
                InfoTable.AddColumn("ΣΥΝΟΛΟ", InfoTable.COLUMN_TYPE_NUMBERS)
                Dim dataList As List
                dataList.Initialize
                
                LotLbl.Text =  "LOT: " & jmap.Get("LOT")
                ProvLbl.Text =  "Προμηθευτής: " & jmap.Get("ΠΡΟΜΗΘΕΥΤΗΣ")
                PerLbl.Text =  "Περιγραφή: " & jmap.Get("ΠΕΡΙΓΡΑΦΗ ΕΙΔΟΥΣ")
                MeasurLbl.Text =  "Μονάδα Μέτρησης: " & jmap.Get("ΜΟΝΑΔΑ ΜΕΤΡΗΣΗΣ")
                CodeLbl.Text =  "Κωδικός Είδους: " & jmap.Get("ΚΩΔΙΚΟΣ ΕΙΔΟΥΣ")               
                
                For Each coljRoot As Map In jRoot
                    
                    Dim spot As String = coljRoot.Get("ΘΕΣΗ")
                    Dim status As String = coljRoot.Get("STATUS")                   
                    Dim sum As Float = coljRoot.Get("ΣΥΝΟΛΟ")
                                    
                    Dim responseArray As List
                    responseArray.Initialize()
                    responseArray = Array( spot, status, sum)
                    dataList.Add(responseArray.As(List))
                Next               
                InfoTable.SetData(dataList)
                
            Else If prefix = "91" Then

'               One tab only here
                InfoPanelScroll.AddView(InfoPanelStrip,0,0,InfoScrollPanel.Width, InfoScrollPanel.Height)
                InfoScroll.LoadLayout("Lay_InfoScroll", "Βασικές Πληροφορίες")
                
                LotLbl.Text =  "LOT: " & jmap.Get("LOT")
                ProvLbl.Text =  "Προμηθευτής: " & jmap.Get("ΠΡΟΜΗΘΕΥΤΗΣ")
                PerLbl.Text =  "Περιγραφή: " & jmap.Get("ΠΕΡΙΓΡΑΦΗ ΕΙΔΟΥΣ")
                MeasurLbl.Text =  "Status: " & jmap.Get("STATUS")
                CodeLbl.Text =  "Κωδικός Είδους: " & jmap.Get("ΚΩΔΙΚΟΣ ΕΙΔΟΥΣ")
                ProdNumLbl.Text =  "Αρ. Παρτιδας Παραγωγου: " & jmap.Get("Αρ. Παρτιδας Παραγωγου")               
            Else
                xui.MsgboxAsync("", "ERROR")
            End If
        End If

        j.Release
        
    Catch
        Log(LastException)
    End Try
    If New = "" Then Return
    ScanHereMC.Text = ""
    ScanHereMC.RequestFocus()

End Sub

I hope it helps and that someone can give me a solution
 

Mahares

Expert
Licensed User
Longtime User
I hope it helps and that someone can give me a solution
Take a look at this short thread which has only 3 posts. It allows you to remove and/or add tabstrips:
 
Upvote 1
Take a look at this short thread which has only 3 posts. It allows you to remove and/or add tabstrips:
I tried using this.
It uses JavaObject, with whichi am not familiar.
Also I get this error when i run my code:
java.lang.reflect.InvocationTargetException
It refers to this line:
Dim p As Panel = jo.GetFieldJO("pages").RunMethod("remove", Array(Index))

Any ideas???
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Any ideas???
I assume you checked JavaObject library in the library pane. I used it to remove tab4. Here is my full code. If it still does not help you, just wait for Erel who wrote it. I used Tabstrip several times, but seldom had a need to use the remove feature:
B4X:
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

Private Sub Button1_Click   'to remove tab with index 4 (5th tab)
    RemovePage (TabStrip1, 4)
End Sub
 
Upvote 0
Top