Android Question GridView of Buttons

josejad

Expert
Licensed User
Longtime User
Hi all:

I'm trying to adapt this B4J sample to B4A

as Erel says:

Well I've followed the steps, replacing "Pane" with "Panel", deleting Base_Resize sub.
Not sure, but I've replaced "Base.AddNode(p, 0, 0, 0, 0)" with "Base.AddView(p, 0, 0, 0, 0)"

When I run the app, I get a blank screen, and I get:
B4X:
Panel size is unknown. Layout may not be loaded correctly.

I get that warning from:
B4X:
Public Sub GetPanel(Column As Int, Row As Int) As Panel
    Return panels(Column, Row)
End Sub
I guess I should set the panel width and height at some point, I've been searching about this, and I've seen Klaus tip here, but I can't figure it out how to do it.

Next step would be make the base? panel scrollable.

BTW, In the original sample, I can't see how Erel sets the panels position.

See attached a small project.

Thanks
 

Attachments

  • Grid.zip
    11.1 KB · Views: 381

KZero

Active Member
Licensed User
Longtime User
you missed the dimensions (left,top,width,height)
try this
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    columns = Props.Get("Columns")
    rows = Props.Get("Rows")
    Dim panels(columns, rows) As Panel
    For c = 0 To columns - 1
        For r = 0 To rows - 1
            Dim p As Panel
            p.Initialize("")
            
            panels(c, r) = p
            
        Dim w As Int = Round(200dip / columns)
        Dim h As Int = Round(200dip / rows)
        Dim L,T As Int
        L = r * 200dip
        T = c * 200dip

            p.SetLayout(L, T, w, h)
            
            Base.AddView(p, L,T, 200dip, 200dip)
        Next
    Next
End Sub
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
you missed the dimensions (left,top,width,height)
Thanks kzero, I've modified to adjust the number of panels to activity.

B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
    mBase = Base
    columns = Props.Get("Columns")
    rows = Props.Get("Rows")
    Dim xscale As Int= mBase.Width / columns
    Dim yscale As Int= mBase.Height / rows
    Dim panels(columns, rows) As Panel
    For c = 0 To columns - 1
        For r = 0 To rows - 1
            Dim p As Panel
            p.Initialize("")
            panels(c, r) = p
            Dim w As Int = Round(xscale)
            Dim h As Int = Round(yscale)
            Dim L,T As Int
            L = r * xscale
            T = c * yscale
            p.SetLayout(L, T, w, h)
            Base.AddView(p, L,T, xscale, yscale)
        Next
    Next
End Sub

Now I will try with the scrollview Panel.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
There is really no reason to use that code in B4A. It is useful in B4J where the grid can be resized. This is not the case in Android.
Erel, the code is to create the view, not for the resize event
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…