Android Question Scrollview_ScrollChanged not working

rscheel

Well-Known Member
Licensed User
Longtime User
I'm designing a mobile app with connection to a remote bd, the carfo elements in a scrollview, the problem I have is that the event does not work Scrollview_ScrollChanged does nothing.

Thank you.

B4X:
Sub Process_Globals
    Dim t As Timer
End Sub

Sub Globals
    Private BarraEstadoMain As ACToolBarLight
    Private Scrollview As ScrollView
    Private PanelContMain As Panel
    Private ServerIP As String
    Private Panel1 As Panel
    Private texto1 As Label
    Private texto2 As Label
    Private texto3 As Label
    'Dim anim As Animation
    Private PanelFiltro As Panel
    'Private Spinner1 As Spinner
    'Private Filtro As Label
    Private ImageView1 As ImageView
    Dim btnTest As Button
 
    Private Fab1 As FloatingActionButton

    'Private mLastScrollY As Int = 0
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("LayoutMain")
    BarraEstadoMain.SetAsActionBar
    BarraEstadoMain.Title = "Lista"
    BarraEstadoMain.InitMenuListener
    ServerIP="http://miservidor/db.php"
    Datos_PHP
End Sub

Sub Activity_CreateMenu(Menu As ACMenu)
    Private ACSubmenu As ACSubMenu
    Menu.Clear
    Menu.Add(1, 3, "Opción1", Null)
    Menu.Add(2, 4, "Opción2", Null)
    Menu.Add(3, 5, "Opción3", Null)
    ACSubmenu = Menu.AddSubMenu(1, 4, 6, "Submenu")
    ACSubmenu.Add(101, 1, "Submenu Item 1", Null)
    ACSubmenu.Add(102, 2, "Submenu Item 2", Null)
End Sub

Sub BarraEstadoMain_MenuItemClick (Item As ACMenuItem)
    Log("Menu Item Clicked: " & Item.Id & " - " & Item.Title)
    ToastMessageShow("Menu Item Clicked: " & Item.Id & " - " & Item.Title, False)
End Sub

Sub GetData(SQL_Pre As String, sJob As String)
    Dim GetSQL As HttpJob
    GetSQL.Initialize(sJob, Me)
    GetSQL.download2(ServerIP, Array As String ("SQL", SQL_Pre)) 
End Sub

Sub Datos_PHP
    GetData("SELECT * FROM mitabla;","GetOfert")
End Sub

Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
             Dim res As String
            res = Job.GetString
            Log("Back from Job:" & Job.JobName )
            Log("Job Text: " & res)
            Dim parser As JSONParser
            parser.Initialize(res)
        Select Job.JobName
            Case "GetOfert"
                    Dim ListMode As List
                    Dim lst As List 
                    lst.Initialize
                    ListMode = parser.NextArray 'returns a list with maps
                If ListMode.Size == 0 Then
                    ToastMessageShow("No hay registros", True)
                Else
                    Scrollview.Initialize(56dip *1)
                    Activity.AddView(Scrollview, 0, 0, 100%x, 100%y)
                    Scrollview.Panel.Height = 127dip * ListMode.Size '127dip
                    'Scrollview.Panel.LoadLayout("LayoutMain") 
                        'Filtro.Initialize("")
                        'Filtro.Text = "Filtrar: "
                        'Filtro.TextColor = Colors.Blue
                        PanelFiltro.Initialize("panelFiltro")
                        PanelFiltro.Color=Colors.RGB(230,126,34)
                        Scrollview.Panel.AddView(PanelFiltro,0%x,53dip,100%x,180dip)
                        PanelFiltro.Elevation = 8dip
                        'Scrollview.Panel.AddView(Spinner1,25%x,20dip,230dip,20dip)
                     
                            'Load a Drawable for the icon
                            Dim xml As XmlLayoutBuilder
                            Fab1.Initialize("Fab1")
                            Fab1.Icon = xml.GetDrawable("ic_add_white_24dp")
                            Fab1.Color = Colors.RGB(30,50,190)
                            Fab1.ColorPressed = Colors.RGB(50,70,210)
                            Fab1.ColorRipple = Colors.RGB(90,110,250)
                            Scrollview.Panel.AddView(Fab1,80%x,200dip,56dip,56dip)
                            'Set the offset of hide position. This is the amount the FAB moves on hide.
                            Fab1.HideOffset = 100%y - Fab1.Top
                            Fab1.Hide(False)

                            'Set up a timer to show the FAB delayed.
                            t.Initialize("Timer", 300)
                            t.Enabled = True

                    For i = 0 To ListMode.Size -1
                        Dim ListaData As Map
                        ListaData = ListMode.Get(i)
                        'lst.Add(Mode.GEt("Modelo"))
                        'ToastMessageShow(ListaData.Get("titulo"), False)
                        Panel1.Initialize("panel"&i)
                 
                        Panel1.Color=Colors.White ' el color que tu quieras
                        Scrollview.Panel.AddView(Panel1,2%x,((i+2)*127dip),96%x,110dip) '127dip),96%x,110dip)
                        'anim.InitializeTranslate("anim", 0, 0, 0, -200dip)
                           'anim.Duration = 500
                        'anim.Start(Panel1)
                     

                        Panel1.Elevation = 5dip
                     
                        Dim gd As GradientDrawable
                           gd.Initialize("TR_BL", Array As Int(Colors.White, Colors.White))
                           gd.CornerRadius = 2dip
                           Panel1.Background = gd
                     
                        texto1.Initialize("etiqueta")
                        texto1.TextColor = Colors.Black ' el color que tu quieras
                        texto1.Text = ListaData.Get("countryName")
                        Panel1.AddView(texto1,10dip,(10dip),100%x,50%y)
                     
                        texto2.Initialize("etiqueta")
                        texto2.TextColor = Colors.Black ' el color que tu quieras
                        texto2.Text = ListaData.Get("capital")
                        Panel1.AddView(texto2,10dip,(40dip),100%x,50%y)
                     
                        texto3.Initialize("etiqueta")
                        texto3.TextColor = Colors.Blue ' el color que tu quieras
                        texto3.Text = ListaData.Get("continentName")
                        Panel1.AddView(texto3,10dip,(70dip),100%x,50%y)

                        ImageView1.Initialize("ImageView1")
                        'ImageView1.Bitmap = LoadBitmap(File.DirRootExternal & "/Download", "alexandra.gif" )
                        GetPicasso.RunMethodJO("load", Array("http://i.imgur.com/DvpvklR.png")).RunMethodJO("into", Array(ImageView1))
                        ImageView1.Gravity = Gravity.FILL
                        Panel1.AddView(ImageView1,68%x, 10dip, 90dip, 90dip)
                     
                        btnTest.Initialize("btnTest")
                        Panel1.AddView(btnTest,55%x, 55dip, 50dip, 50dip)
                        btnTest.Tag= ListaData.Get("countryName")
                           btnTest.Text="IR"
                     
                    Next
                End If 
    End Select
    End If
End Sub

Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub

Sub GetPicasso As JavaObject
   Dim jo As JavaObject
   'com.squareup.picasso.Picasso.with(context)
   Return jo.InitializeStatic("com.squareup.picasso.Picasso").RunMethod("with", Array(GetContext))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
 
End Sub

Sub btnTest_Click
    Dim Send As Button
 
    Send=Sender
    ToastMessageShow("Button "&Send.Tag, False)
End Sub

Sub Fab1_Click
    If Fab1.IsShowing Then
        Fab1.Hide(True)
        t.Interval = 300
        t.Enabled = True
    End If
End Sub

Sub Timer_Tick
    Fab1.Show(True)
    t.Enabled = False
End Sub

'If we scroll up or down the FAB is hidden or shown again.

Sub Scrollview_ScrollChanged(Position As Int)
    ToastMessageShow(Position,False)
    Log(Position)
    If Position > 3dip Then
        Fab1.Hide(True)
    Else
        Fab1.Show(True)
    End If
 
'    If Abs(Position - mLastScrollY) > 3dip Then
'        If Position > mLastScrollY Then
'            Fab1.Hide(True)
'        Else
'            Fab1.Show(True)
'        End If
'    End If
'    mLastScrollY = Position
End Sub

Screenshot_20160719-105110.png
 
Last edited:

mangojack

Well-Known Member
Licensed User
Longtime User
should be ..
B4X:
Scrollview.Initialize2(56dip*1, "Scrollview")

Initialize2
Similar to Initialize. Sets the Sub that will handle the ScrollChanged event.

also ( 56dip* 1 .... is that not still 56dip ??
 
Last edited:
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
should be ..
B4X:
Scrollview.Initialize2(56dip*1, "Scrollview")

Initialize2
Similar to Initialize. Sets the Sub that will handle the ScrollChanged event.

also ( 56dip* 1 .... is that not still 56dip ??

Dear thousand thanks works perfect, sometimes you do not see the mistakes, so we must take the opinion of others, about the 56dip * 1, really they do nothing no function place it there just for Initializing the scrollview with some value.
 
Upvote 0
Top