Android Question [SOLVED] Logic to arrange the button

AisyahHei

New Member
Hi! I am new in using B4A.

May I know, what and how can we do to wrap the button or items in the panel to the next row or column when the panel is out of the room? I want to make a panel that can hold many buttons by codes but it will be out from the panel. I want to make the button go to the next row when the button is exceeding the panel width.

And if you don't mind, I want to know too about how we can keep the buttons on the p_stock_all when the button on p_stock_all is clicked. Because in the code, I used p_stock_all.RemoveAllViews but it will clear all the buttons in p_stock_all when I want it to stay and clear only when the other button on p_stock is clicked. Hope you guys can help me...

B4X:
Sub Buttons
    
    Dim CursorButton As Cursor
    Dim id As Int
    
    CursorButton = localsql.ExecQuery("SELECT * from b_stock_cat")
    
    For i = 0 To CursorButton.RowCount-1
            CursorButton.Position = i
            Dim ButtonX As Button
            Dim PosX As Pos
            PosX.x = i
            PosX.y = i+10
            ButtonX.Initialize("Button")
             ButtonX.Tag = PosX
            ButtonX.Text=CursorButton.GetString("b_stock_cat_cat")
            ButtonX.TextSize=12
            
            p_stock.AddView(ButtonX,8,(i*130),250,140)
        
    Next
End Sub

Sub Button_Click
    p_stock_all.RemoveAllViews

    Dim Button1 As Button
    Dim name As String
    Button1 = Sender
    
    Dim Pos1 As Pos
    Pos1 = Button1.Tag
    
    Dim CursorButton As Cursor
    CursorButton = localsql.ExecQuery("SELECT b.*, c.b_stock_cat_cat from b_stock b, b_stock_cat c WHERE (b.b_stock_cat_id = c.id) AND (b.or_id ='1' AND b.ou_id='1') AND c.b_stock_cat_cat = '"&Button1.Text&"'")
    
    For i = 0 To CursorButton.RowCount-1
        CursorButton.Position = i
        Dim PosX As Pos
        PosX.x = i
        PosX.y = i+10
        Button1.Initialize("Button")
        Button1.Tag = PosX
        Button1.Text=CursorButton.GetString("b_stock_name")
        Button1.TextSize=10
        p_stock_all.AddView(Button1,(i*180),10,180,150)
        
    Next
    
End Sub
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
There are many ways of doing this. Here is an example using a scroll view. I think that it is what you mean when you say "doing some logic on the area of the activity". You will need to adapt the example to fit in with the rest of your layout. This does not not use "LoadLayout". If you are loading a layout then create the scroll view in the layout but construct the buttons in code in your activity. There are many ways to use the tag property of the buttons to connect with the data items, including loading complete objects to the tags.
 

Attachments

  • buttons.zip
    8.7 KB · Views: 142
Upvote 0

AisyahHei

New Member
There are many ways of doing this. Here is an example using a scroll view. I think that it is what you mean when you say "doing some logic on the area of the activity". You will need to adapt the example to fit in with the rest of your layout. This does not not use "LoadLayout". If you are loading a layout then create the scroll view in the layout but construct the buttons in code in your activity. There are many ways to use the tag property of the buttons to connect with the data items, including loading complete objects to the tags.
Thank you, I think I understand the code you gave. I will try to adapt it in my code. I will ask again if I have further question :)
Edited: Thank you so much. There is no problem and I can get exactly like what I want. šŸ˜
 
Last edited:
Upvote 0
Top