Android Question Change Listview item

fernando.oliboni

Active Member
Licensed User
Longtime User
How can I change the font color and size of the last item on the list?
1606585936747.png


B4X:
lista_orcamentos.AddTextItem("Voltar para Tela de Orçamentos" , "Voltar para Tela de Orçamentos")
 

Mahares

Expert
Licensed User
Longtime User
How can I change the font color and size of the last item on the list?
When you use listview or customlistview with the AddTextItem approach, you cannot selectively change the color of one item. To be able to do it, you have to switch to using customlistview with the items layout approach.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Try with CSbuilder

 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I don't see how he can have a different font and color for the last item in the customlistview item using AddTextItem (remember, he only wants the last item changed). But, I know it can be done with a label loaded onto a panel (items layout). I can post code if the OP is interested in the latter solution.
If you think you can change the last item color and font using AddTextItems, I would love to see a snippet.
There are several ways to get a different color for a native ListView item.

Using CSBuilder is one way.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Using CSBuilder is one way.
Ok. I investigated it further Here is the code for displaying the last item in blue:
B4X:
Dim j As Int    
    For Each s As String In MyList
        clv1.AddTextItem(s, s)
        If j=MyList.Size -1 Then
            Dim cs As CSBuilder
            cs.Initialize.Bold.size(40).color(Colors.Blue).Append($"${s}"$).popall
            clv1.AddTextItem(cs, s)
        End If
        j=j+1
    Next
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
There isn't a single good reason to use ListView. Don't waste your time.
Although the OP used the word listview, I really think he meant and was using a customlistview. Take a look at his first post line of code. It is a customlistview line not listview line. That is why I posted the pertinent code in post #5 for an xClv he can use.
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
[QUOTE = "Mahares, postagem: 780465, membro: 16350"]
Está bem. Eu investiguei mais aqui. Aqui está o código para exibir o último item em azul:
[código] Dim j As Int
For each s As String In MyList
clv1.AddTextItem (s, s)
Se j = MyList.Size -1 Then
Dim cs As CSBuilder
cs.Initialize.Bold.size (40) .color (Colors.Blue) .Append ($ "$ {s}" $). popall
clv1.AddTextItem (cs, s)
Fim se
j = j + 1
Próximo [/ code]
[/CITAR]



Muito obrigado pela atenção. Seu exemplo funcionou. Gostei da dica. Também irei dar uma olhada no xCustomListView como Erel sugere.
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
[QUOTE = "Star-Dust, postagem: 780464, membro: 101440"]
Existem várias maneiras de obter uma cor diferente para um item ListView nativo.

Usar o CSBuilder é uma maneira.
[/ CITAR]

Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Although the OP used the word listview, I really think he meant and was using a customlistview. Take a look at his first post line of code. It is a customlistview line not listview line. That is why I posted the pertinent code in post #5 for an xClv he can use.
You are of course correct!
 
Upvote 0
Top