How to do that (scrolling Buttons)

vinians

Member
Licensed User
Longtime User
[SOLVED] How to do that (scrolling Buttons)

I created this code to put a variable number of buttons inside a ScrollView, but the buttons arent showing up.... see below:
B4X:
Sub HTTP_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Dim col, lin As Int
   Dim w, h     As Int
   Dim sep, p   As Int
   Dim aux      As String
   Dim pn       As Panel
   
   Dim sv       As ScrollView
    sv.Initialize(0)
    Activity.AddView(sv, _ 
                0, _ 
                lblSelecioneProduto.Top + lblSelecioneProduto.Height, _ 
                 100%x, _ 
                100%y - (lblSelecioneProduto.Top + lblSelecioneProduto.Height))
   
   Log("ResponseSuccess")
   ProgressDialogHide()
   If (Funcoes.PreparaResposta(Response.GetString("UTF8")) = "OK") Then
      col  = 0
      lin  = 0
      sep  = 10dip
      w    = (100%x / 2) - sep
      h    = 10%y
      For i = 0 To Funcoes.g_resposta.Size - 1
         aux = Funcoes.g_resposta.Get(i)
         If (aux.Trim = "") Then Continue
         Log(aux)
         Dim b As Button
         b.Initialize("btnProduto")
         pn = sv.Panel
         pn.AddView(b, 0, 0, 0, 0)
         b.Height = h
         b.Width  = w
         b.Top    = lblSelecioneProduto.Top + lblSelecioneProduto.Height + 5dip +  ((h + sep) * lin)
         p        = aux.IndexOf(";")
         If (p = -1) Then Continue
         b.Tag    = Floor(aux.SubString2(0, p))
         If (col = 0) Then 
            b.Left = sep
         Else
            b.Left = sep + w + sep
         End If
         b.TextSize   = 22
         b.Text       = aux.SubString(p + 1)
         b.Background = Funcoes.StateListDrawable(Colors.RGB(32,234,159), Colors.RGB(20,61,27), Colors.Rgb(32,234,159), Colors.RGB(20,61,27), 10dip, "TOP_BOTTOM", "BOTTOM_TOP")
         'b.Typeface   = Typeface.STYLE_BOLD
         col = col + 1
         If (col > 1) Then 
            col = 0
            lin = lin + 1
         End If
      Next         
   Else
      Funcoes.Erro(Funcoes.g_ultimo_erro)   
      Activity.Finish()
   End If
End Sub
What's wrong?
Thanks in advance!
 
Last edited:

klaus

Expert
Licensed User
Longtime User
You have never reset the height of the internal panel of the ScrollView !
IYou set it to 0 when you initialized it !
At the end of filling the ScrollView you must set the internal Panel height according to the views you added.

Best regards.
 
Upvote 0
Top