Android Question loading layout in a panel

apty

Active Member
Licensed User
Longtime User
i am having trouble with the below code. The layout is not loaded, i just get a blank screen.

B4X:
Dim pnlx As Panel
    pnlx.Initialize("")
    pnlx.LoadLayout("products")
    Activity.AddView(pnlx,0dip,0dip,100%x,100%y)

What could be wrong?
 

apty

Active Member
Licensed User
Longtime User
this works but what of cases where i need to load layouts in a scrollview like in the example below? The below code also gives me a blank screen.

B4X:
Dim btnx As Int=0
    For i=0 To 6
        Dim pnlx As Panel
        Dim lblCategory As Label
        Dim pnlCategoryItems As Panel
        Dim imgCategory As ImageView
        'Dim Panel1 As Panel
        
        pnlx.Initialize("")
        pnlx.LoadLayout("categories")
        
        If i=0 Then
            
            lblCategory.Text="Bc"
            imgCategory.Bitmap=LoadBitmap(File.DirAssets,"bd.png")
            Else if i=1 Then
            lblCategory.Text="Cx"
            imgCategory.Bitmap=LoadBitmap(File.DirAssets,"cx.png")
        End If
        
        ScrollViewMain.Panel.AddView(pnlx, 0,btnx,100%x,290dip)
        
        
        btnx=btnx+290dip
    Next
    ScrollViewMain.panel.Height=btnx
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
pnlx.Initialize("")
B4X:
pnlx.Initialize("")
pnlx.setlayout(.....)

The panelsize must be known. add the panel to the activity and remove it after you loaded the layout. Otherwise you need to define the panels size.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
strange enough, the same code works in another project. The below code works but on a different project. i just copied the same code to the current project and it doesn't work.

B4X:
Dim btnx As Int=0
    For i = 0 To 5
        Dim panelx As Panel
        Dim lblNames As Label
        Dim lblPass As Label
        Dim lblCost As Label
       
       
       
        panelx.Initialize("")
        panelx.LoadLayout("summary")
        lblNames.Text="test"
       
        lblPass.Text="test"
        lblCost.Text=500

        ScrollView1.Panel.AddView(panelx, 0,btnx,98%x,60dip)
        btnx=btnx+80dip

    Next
   
    ScrollView1.panel.Height=btnx
 
Upvote 0
Top