Android Question How to avoid duplication ?

ciprian

Active Member
Licensed User
Longtime User
Hi there... need some help to avoid duplication in this code.
B4X:
'***************View Pager Settings*******************
    container.Initialize
        For i = 1 To 10
            Dim pan As Panel
            Select i
                Case 1
                    pan = CreatePanel(TYPE_1, "1")
                    container.AddPage(pan,"1")
                Case 2
                    pan = CreatePanel(TYPE_2, "2")
                    container.AddPage(pan,"2")
                Case 3
                    pan = CreatePanel(TYPE_3, "3")
                    container.AddPage(pan,"3")
                Case 4
                    pan = CreatePanel(TYPE_4, "4")
                    container.AddPage(pan,"4")
                Case 5
                    pan = CreatePanel(TYPE_5, "5")
                    container.AddPage(pan,"5")
                Case 6
                    pan = CreatePanel(TYPE_6, "6")
                    container.AddPage(pan,"6")
                Case 7
                    pan = CreatePanel(TYPE_7, "7")
                    container.AddPage(pan,"7")
                Case 8
                    pan = CreatePanel(TYPE_8, "8")
                    container.AddPage(pan,"8")
                Case 9
                    pan = CreatePanel(TYPE_9, "9")
                    container.AddPage(pan,"9")
                Case 10
                    pan = CreatePanel(TYPE_10, "10")
                    container.AddPage(pan,"10")
            End Select
        Next
    pager.Initialize(container, "Pager")
    AD.NavDrawer.ContentPanel.AddView(pager, 0, 0, AD.NavDrawer.ContentPanel.Width, AD.NavDrawer.ContentPanel.Height)
 

MaFu

Well-Known Member
Licensed User
Longtime User
B4X:
'***************View Pager Settings*******************
    container.Initialize
        For i = 1 To 10
            Dim num As String
            num = i
            Dim pan As Panel
            pan = CreatePanel(TYPE_1, num)
            container.AddPage(pan,num)
        Next
    pager.Initialize(container, "Pager")
    AD.NavDrawer.ContentPanel.AddView(pager, 0, 0, AD.NavDrawer.ContentPanel.Width, AD.NavDrawer.ContentPanel.Height)
 
Upvote 0

ciprian

Active Member
Licensed User
Longtime User
You are right, it works.
I was complicating my life for nothing with 10 diferent types of panel....
Your code works like a charm. Thanx
 
Upvote 0
Top