Android Question Grid View control

Patrick Clark

Active Member
Licensed User
Hi I am looking for a grid view that behaves like CustomListView but can have columns as well as rows.

What I want to achieve is a scrolling grid (only needs to scroll up and down) where each cell can hold a layout. (I need to be able to access each item in the layout like the GetView from CustomListView)

For my purposes each cell can have the same layout but it would be nice to be able to specify different layouts for each cell.

Any suggestions greatly received.
 

derez

Expert
Licensed User
Longtime User
If you look at Erel's example of xcustomlistview, there is a layout of cellitem. You can create your own cellitem design and adapt the code to access each view in the design.
To load different items layout you'll have to modify this sub:
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int, something as boolean) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    if something then
         p.LoadLayout("CellItem1")
    else
         p.LoadLayout("CellItem2")
    end if
    Label1.Text = Text
    Return p
End Sub
To load the required layout per case.
 
Last edited:
Upvote 0

Patrick Clark

Active Member
Licensed User
If you look at Erel's example of xcustomlistview, there is a layout of cellitem. You can create your own cellitem design and adapt the code to access each view in the design.
To load different items layout you'll have to modify this sub:
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("CellItem")
    Label1.Text = Text
    Return p
End Sub
To load the required layout per case.

Yes, I get that but the xCustomListView only has one column. It is a list not a grid
 
Upvote 0

derez

Expert
Licensed User
Longtime User
the xCustomListView only has one column. It is a list not a grid
Yes but in each column item you can have few views in a row like a one row in a grid and refer to each view separately.
In the example you can click the button and /or check the box...
 
Upvote 0

Patrick Clark

Active Member
Licensed User
I think you are suggesting I have each CustomListView layout repeat the view for each column. EG. If I want 3 columns then the layout would have label1, label2 and label3

Doing that I cannot change the number of columns dependent on screen size and I would have to hide views if there wasn't enough information to fill a row. I can't see how that would work.

----------

This is what I am trying to achieve but with a generic format for each cell.

https://www.b4x.com/android/forum/threads/sd-menuextender.88991/
 
Upvote 0
Top