Italian Colori nella ListView

MaAncheNo

Member
Licensed User
Longtime User
Salve,

vorrei usare una Listview a due righe colorando, in base ad una variabile, il testo della seconda riga.
Il codice sotto non funziona, la seconda riga si colora a c.. cavolo, addirittura se tolgo lo Sleep(0) assume un solo colore.
Avete altri metodi?


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private ListView1 As ListView
    Private cnt As Int
    Private value As Int
    Private label1 As Label
    Private label2 As Label
    Private colore As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    label1 = ListView1.TwoLinesLayout.Label
    label2 = ListView1.TwoLinesLayout.SecondLabel
    For cnt = 0 To 20
    value = Rnd(1,50)
        Select True
            Case value < 0
                label1.TextColor = Colors.Magenta
                label2.TextColor = Colors.Magenta
                colore = "magenta"
            Case value >= 0 And value < 6
                label1.TextColor = Colors.Green
                label2.TextColor = Colors.Green
                colore = "verde"
            Case value > 5 And value < 16
                label1.TextColor = Colors.Yellow
                label2.TextColor = Colors.Yellow
                colore = "giallo"
            Case value > 15 And value < 31
                label1.TextColor = Colors.RGB(0xFF, 0x8C, 0x00)
                label2.TextColor = Colors.RGB(0xFF, 0x8C, 0x00)
                colore = "arancione"
            Case value > 30
                label1.TextColor = Colors.Red
                label2.TextColor = Colors.Red
                colore = "rosso"
        End Select
        Sleep(0) ' Se lo tolgo diventa un solo colore
        ListView1.AddTwoLines(value, colore)
    Next
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
Mi pare che non puoi colorare ogni rigo di un colore diverso.
Prova con XCustomListView oppure Creati una ListView personalizzata con ScrollView e una serie di Label
 

MaAncheNo

Member
Licensed User
Longtime User
Per lo sfondo ero sicuro che non si potesse fare ma per il testo ero incerto, anche perché in effetti il colore cambia ma non sempre secondo quanto indicato dal codice.
Pazienza cambierò componente, Grazie!
 

Attachments

  • Screenshot_20181115-155503.jpg
    Screenshot_20181115-155503.jpg
    150.2 KB · Views: 182

Star-Dust

Expert
Licensed User
Longtime User
Per lo sfondo ero sicuro che non si potesse fare ma per il testo ero incerto, anche perché in effetti il colore cambia ma non sempre secondo quanto indicato dal codice.
Pazienza cambierò componente, Grazie!
Cambia perché tu cambi le impostazioni e le Label successive prendono le proprietà nuove.

Ma non è permanente al primo refresh vengono usate le ultime proprietà settate
 
Last edited:

PCastagnetti

Member
Licensed User
Longtime User
puoi utilizzare un CSBuilder per ottenere layout con colori diversi:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private cs As CSBuilder
    Private ListView1 As ListView
    Private cnt As Int
    Private value As Int
    Private label1 As Label
    Private label2 As Label
    Private colore As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim tmpBmp As Bitmap
  
    tmpBmp.Initialize(File.DirAssets, "Immaginetest.png")
   
Activity.LoadLayout("Layout1")
 
   ListView1.AddTwoLinesAndBitmap(cs.Initialize.Color(Colors.Red).Append("Inserisci il testo").PopAll,cs.Initialize.Color(Colors.blue).Append("Inserisci il Testo 2").PopAll,tmpBmp)
 ListView1.AddTwoLinesAndBitmap(cs.Initialize.Color(Colors.green).Append("Inserisci il testo").PopAll,cs.Initialize.Color(Colors.blue).Append("Inserisci il Testo 2").PopAll,tmpBmp)
...........................
 

MaAncheNo

Member
Licensed User
Longtime User
puoi utilizzare un CSBuilder per ottenere layout con colori diversi:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private cs As CSBuilder
    Private ListView1 As ListView
    Private cnt As Int
    Private value As Int
    Private label1 As Label
    Private label2 As Label
    Private colore As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Dim tmpBmp As Bitmap
 
    tmpBmp.Initialize(File.DirAssets, "Immaginetest.png")
  
Activity.LoadLayout("Layout1")
 
   ListView1.AddTwoLinesAndBitmap(cs.Initialize.Color(Colors.Red).Append("Inserisci il testo").PopAll,cs.Initialize.Color(Colors.blue).Append("Inserisci il Testo 2").PopAll,tmpBmp)
 ListView1.AddTwoLinesAndBitmap(cs.Initialize.Color(Colors.green).Append("Inserisci il testo").PopAll,cs.Initialize.Color(Colors.blue).Append("Inserisci il Testo 2").PopAll,tmpBmp)
...........................
E' perfettissima per le mie necessità! Grazie!!!:D
 
Top