Android Question Duplicate ListView

rbk

Member
Licensed User
Longtime User
Hi

My application get data from a remote mysql database using a json web service (php file), then I load this data in a ListView using "HttpUtils2Service" and "HttpJob".

In some occasions the entire ListView is duplicated right under the first one and the scroll attribute from the ListView stop working. I attached the correct view of the Layout and the wrong one, so you can see what is all about.

The same behavior is happening in others activities from the app.

Here is the code from the Activity.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private ALERT_DESCRIPTION = "alert_description" As String
    Dim bCloseSession2 = False As Boolean
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Type TwoLines (First As String, Second As String)
    Dim imgVolver As ImageView
    Dim lvAlert As ListView
    Dim bValidaRed As Boolean
    Dim pMensaje As Panel
    Dim lblMensaje As Label
    Dim btnReintentar As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frm_descripcion_alertas")
   
    'Carga las descripciones de las alertas validando en primera instancia si hay conexion
    bValidaRed = Globales.ValidateConnection
    If bValidaRed = True Then
        FetchAlertList
    Else
        lblMensaje.Text = "Fallo en conexion"
        pMensaje.Visible = True
    End If
End Sub

Sub Activity_Resume
    If bCloseSession2 = True Then
         Activity.Finish
         bCloseSession2 = False
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
'Evento para volver a Principal
Sub imgVolver_Click   
    StartActivity(Principal)
End Sub
'Busca las descripciones de las alertas
Sub FetchAlertList
    pMensaje.Visible = False
    lvAlert.Clear
    ProgressDialogShow2("Cargando..",False)
    Globales.ExecuteRemoteQuery("SELECT id, name, description_mobile FROM tizon.alerttypes ORDER BY id", ALERT_DESCRIPTION, Me)
End Sub
'Proceso donde se obtienen los datos del ws
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Dim sRes As String
        Dim bmBrown As Bitmap
        Dim bmBlue As Bitmap
        Dim bmGreen As Bitmap
        Dim bmYellow As Bitmap
        Dim bmOrange As Bitmap
        Dim bmRed As Bitmap
        Dim bmWhite As Bitmap
   
           bmBrown.Initialize(File.DirAssets, "brown.png")
        bmBlue.Initialize(File.DirAssets, "blue.png")
        bmGreen.Initialize(File.DirAssets, "green.png")
        bmYellow.Initialize(File.DirAssets, "yellow.png")
        bmOrange.Initialize(File.DirAssets, "orange.png")
        bmRed.Initialize(File.DirAssets, "red.png")
        bmWhite.Initialize(File.DirAssets, "white.png")
           
        sRes = Job.GetString
        Dim parser As JSONParser
        parser.Initialize(sRes)
        Dim ALERTS As List
        ALERTS = parser.NextArray 'returns a list with maps
       
        For i = 0 To ALERTS.Size - 1
            Dim m As Map
            m = ALERTS.Get(i)
            Dim tl As TwoLines
            tl.First = m.Get("name")
            tl.Second = m.Get("description_mobile")
            lvAlert.TwoLinesAndBitmap.Label.TextSize = 15
            lvAlert.TwoLinesAndBitmap.SecondLabel.TextSize = 10
                                   
            Select  m.Get("id")
                Case "1" 'Alerta Cafe
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmBrown)
                Case "2" 'Alerta Azul
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmBlue)
                Case "3" 'Alerta Verde
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmGreen)
                Case "4" 'Alerta Amarilla
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmYellow)
                Case "5" 'Alerta Naranja
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmOrange)
                Case "6" 'Alerta Roja
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmRed)
                Case "7" 'Alerta Blanca
                    lvAlert.AddTwoLinesAndBitmap(tl.First, tl.Second, bmWhite)
            End Select
           
        Next
    Else
        lblMensaje.Text = "Fallo conexion servidor"
        pMensaje.Visible = True
    End If
    Job.Release
End Sub
'Deshabilita back button
Sub Activity_KeyPress (KeyCode As Int) As Boolean                           
    If KeyCode = KeyCodes.KEYCODE_BACK Then                                   
        Return True
    Else
        Return False
    End If
End Sub
'Evento que permite reintentar cargar las descripciones en el caso de problemas de conexion
Sub btnReintentar_Click
    bValidaRed = Globales.ValidateConnection
    If bValidaRed = True Then
        FetchAlertList
        pMensaje.Visible = False
    End If
End Sub


Hope someone can help. I looked everywhere for a solution or clue of what is going on, but nothing.
 

Attachments

  • Screenshot_good.png
    Screenshot_good.png
    165.1 KB · Views: 172
  • Screenshot_error.png
    Screenshot_error.png
    187.1 KB · Views: 169

DonManfred

Expert
Licensed User
Longtime User
I would suggest putting some LOG-statements into the program-flow to see what happen. with seeing just this part of your code (instead of project - export as zip) it is hard to help.

But your code looks ok for me. Even if i dont understand the language of your comments ;-)

If i should give a guess what happen i would say you are calling "FetchAlertList" twice (or the resulting json from php-file give doublicate answers)

Can you post the result-json?
B4X:
log(sRes)' in your JoobDone
 
Last edited:
Upvote 0
Top