Android Question Frozen ListView Problem

Edoardo Antonucci

Member
Licensed User
Goodmorning everyone.

In an very simple activity of my app I load a layout that, in the second half of the screen, has a listview and two buttons. So via code I create and populate a scrollist in the first half of the screen,
B4X:
    For Each l_Attivita As Ty_Attivita In l_ListaAttivita
        If l_Attivita.DataOraFine = 0 Then
            l_idAttivitaCorrente = l_Attivita.id
        End If
        DateTime.TimeFormat = "HH:mm"
        row (0) = l_Attivita.DescrizioneAttivita
        row (0) = DateTime.Date(l_Attivita.DataOraInizio) & CRLF & DateTime.Time(l_Attivita.DataOraInizio)
        row (1) = DateTime.Date(l_Attivita.DataOraFine) & CRLF & DateTime.Time(l_Attivita.DataOraFine)
        AddRow(row)
    Next

then i populate the listview

B4X:
    For Each l_Attivita As Ty_TipoAttivita In Starter.a_ClsRuoliTipiAttivita.c_ListaAtt
        lsvTipiAttivita.AddSingleLine(l_Attivita.Descrizione)
    Next

and then i set the enabling of the buttons.

B4X:
If l_idAttivitaCorrente = 0 Then
        btnAvvia.Enabled = True
        btnConcludi.Enabled = False
    Else
        btnAvvia.Enabled = False
        btnConcludi.Enabled = True
    End If

And nothing else.

The listview appears to be frozen. The pressure is not detected (the coloring of the listview element does not change) and the eventual click does not start.
Thanks in advance for those who can help me. Edoardo
 

Edoardo Antonucci

Member
Licensed User
Thanks for your prompt reply.
Here is an extract of the project presenting the problem.
I add further information: before the version with the listview I had tried with a spinner and the result was the same. Even the spinner was frozen
 

Attachments

  • FrozenList.zip
    46.2 KB · Views: 317
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You are adding a scrollview in code with a height of 80%y, even though there are not enough elements to take it down that far so it is not immediately obvious, the scrollview is covering the listview and buttons and capturing the clicks. The scrollview background is transparent.

Why not add the scrollview to the layout?
 
Upvote 0

Edoardo Antonucci

Member
Licensed User
It works!

[QUOTE
Why not add the scrollview to the layout?[/QUOTE]

Oh! A little error that teaches me more about how views work!

To build the table I used an example found in the forum. In this example the scroll list was built from code. But I can actually add it to the layout.

Thank you very much.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
For future reference, when you are adding multiple rows, it would be good to get into the habit of creating a new array each time. It's not a problem for strings, but if you use a different type of table and views or other objects it would cause problems. I would suggest that you do:

B4X:
    Dim row(NumberOfColumns) As String
    row (0) = "Test1"
    row (1) = DateTime.Now
    row (2) = DateTime.Now
    AddRow(row)

    Dim row(NumberOfColumns) As String
    row (0) = "Test2"
    row (1) = DateTime.Now
    row (2) = DateTime.Now
    AddRow(row)
   
    Dim row(NumberOfColumns) As String
    row (0) = "Test3"
    row (1) = DateTime.Now
    row (2) = DateTime.Now
    AddRow(row)

Which you can simplify to:

B4X:
For i = 1 To 3
        Dim row(NumberOfColumns) As String
        row (0) = "Test" & i
        row (1) = DateTime.Now
        row (2) = DateTime.Now
        AddRow(row)
    Next
 
Upvote 0

Edoardo Antonucci

Member
Licensed User
Yes sure. I put it in that form only to remove logic connection to database and make the application.
The routine actually has the structure you suggest. In any case, thanks for the suggestion

B4X:
    Dim l_ListaAttivita As List
    SvuotaScrollList
    SetHeader(h)
    l_idAttivitaCorrente = 0
    If Not(Starter.a_ClsAttivita.LocalLeggi(p_idTurno, p_idUtente)) Then
        ToastMessageShow ("errore nella lettura dei dati d attività da locale", True)
        Return
    End If
    l_ListaAttivita = Starter.a_ClsAttivita.c_Lista
    For Each l_Attivita As Ty_Attivita In l_ListaAttivita
        If l_Attivita.DataOraFine = 0 Then
            l_idAttivitaCorrente = l_Attivita.id
        End If
        DateTime.TimeFormat = "HH:mm"
        Dim row(NumberOfColumns) As String

        row (0) = l_Attivita.DescrizioneAttivita
        row (1) = DateTime.Date(l_Attivita.DataOraInizio) & CRLF & DateTime.Time(l_Attivita.DataOraInizio)
        row (2) = DateTime.Date(l_Attivita.DataOraFine) & CRLF & DateTime.Time(l_Attivita.DataOraFine)
        AddRow(row)
    Next
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
To build the table I used an example found in the forum.
Which example did you use?
I suppose that it's THIS one, this is a very very old one.
If you want to have horizontal scrolling you might consider using the ScrollView2D library.
B4A has changed a lot since this time.
Classes, CustomViews etc.
An evolution of the above example was this one: [Class] TableView - Supports tables of any size
There were several improvements in that thread, ScrollView replaced by ScrollView2D.
Then it was improved by this one: Flexible Table which is a CustomView, based on the ScrollView2D library, perhaps a bit heavy and 'complicated' at the first look.

Then, you might have a look at Erels [B4X] B4XTable - Cross platform, sortable, searchable, customizable table.
It is the most recent one, cross platform and an internal library B4XTable shipped with B4A.
The only drawback, for me, is that it has only horizontal scrolling but no vertical scrolling. It is page based, you need to click on a button to display the next page.

There exist some other ones in the forum, I haven't searched for those.

In your layouts you may also consider the Anchors feature.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…