Italian [risolto] [B4J] custom view

ivanomonti

Expert
Licensed User
Longtime User
Ogni tanto mi viene un embolo "CENTER" è impostato la LABEL, "CENTER" è impostata CVL ma alla fine fa "MISTO LANA", ora si darà colpa al testo che arriva ,a il testo che arriva e formattato normalmente e se lo metto dentro una listview va in centro o destra o sinistra con i soliti "LEFT" - "CENTER", RIGHT".

Di sicuro sbaglio io visto che oggi il tempo non mi aiuta, ma non credo di aver sbagliato qualcosa di cos' colossale.


B4X:
Private Sub hs_Respose(Record As List)
    CustomListView_record.Clear
    For i=0 To Record.Size-1
        Dim m As Map
        m = Record.Get(i)
        Dim lb As Label
        lb.Initialize("")
        lb.Text = m.Get("ms_gpt_01_04").As(String).ToUpperCase & CRLF & CRLF & m.Get("ms_gpt_01_05")
        lb.Tag=m
        If m.Get("badword") = "true" Then
        Else
            CustomListView_record.AddTextItem(lb.Text,lb.Text)
'            lb.PrefHeight = 30
'            lb.Alignment = "CENTER"
            CustomListView_record.Refresh
        End If
    Next
End Sub


1682064515910.png
 

Star-Dust

Expert
Licensed User
Longtime User
Per allineare una multilinea in B4J devi fare così
B4X:
lb.As(JavaObject).RunMethod("setTextAlignment", Array("CENTER"))

Impostare CENTER fra le proprietà ha effetto solo su SingleLine
 

ivanomonti

Expert
Licensed User
Longtime User
Per allineare una multilinea in B4J devi fare così
B4X:
lb.As(JavaObject).RunMethod("setTextAlignment", Array("CENTER"))

Impostare CENTER fra le proprietà ha effetto solo su SingleLine

non da effetto


lb.As(JavaObject).RunMethod("setTextAlignment", Array("CENTER")):
Private Sub hs_Respose(Record As List)
    
    CustomListView_record.Clear
    
    For i=0 To Record.Size-1
        Dim p As Pane
        p.Initialize("")
        p.PrefWidth = CustomListView_record.AsView.Width
        p.PrefHeight = 50
        
        Dim m As Map
        m = Record.Get(i)
        
        Dim str As String = m.Get("ms_gpt_01_04").As(String).Replace(CRLF, "").ToUpperCase.Trim
        
        Dim lb As Label
        lb.Initialize("")
        lb.Text = str
        lb.Tag=m
        
        p.AddNode(lb,0,0,p.PrefWidth,50)
        
        lb.PrefHeight = 50
        lb.Alignment = "CENTER"
        lb.TextColor = fx.Colors.White
        lb.WrapText = True
        CSSUtils.SetBackgroundColor(lb,fx.Colors.ARGB(100,255,0,0))
        
        Dim str As String = m.Get("ms_gpt_01_05").As(String).Replace(CRLF, "").ToLowerCase.Trim
        
        Dim lb As Label
        lb.Initialize("")
        lb.Text = str
        lb.Tag=m
        lb.TextColor = fx.Colors.White
        lb.WrapText = True
        lb.As(JavaObject).RunMethod("setTextAlignment", Array("CENTER"))
        
        If m.Get("badword") = "true" Then
            Continue
        Else
            CustomListView_record.Add(p,p)
            CustomListView_record.AddTextItem(lb.Text,lb)
            CustomListView_record.Refresh
        End If
        
    Next
    
End Sub

1682067641039.png
 

LucaMs

Expert
Licensed User
Longtime User
Non funziona perché quella che vedi non è la label che hai creato, in quanto AddTextItem ha la propria label (e in questo momento, al volo, non ricordo come puoi ottenerla, visto che uso sempre il metodo Add e non AddTextItem).

Cmq, A ME non sembra il caso di centrare il testo, diventerebbe meno leggibile.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Non funziona perché quella che vedi non è la label che hai creato, in quanto AddTextItem ha la propria label (e in questo momento, al volo, non ricordo come puoi ottenerla, visto che uso sempre il metodo Add e non AddTextItem).

Cmq, A ME non sembra il caso di centrare il testo, diventerebbe meno leggibile.
Dovrebbe essere così:
B4X:
Dim lbl As Label
lbl = CustomListView_record.GetPanel(CustomListView_record.Size - 1).GetView(0)
Dopo aver aggiunto l'item, eh.
 

ivanomonti

Expert
Licensed User
Longtime User
Risolto seguendo la logica di Star-Dust non sapevo che alignamento fosse solo sulla prima riga quando poi su design lo fa per tutto il testo (c'è sempre l'inganno) hahahah comuque grazie a tutti ho risolto.


B4X:
Private Sub hs_Respose(Record As List)
    
    CustomListView_record.Clear
    
    For i=0 To Record.Size-1
        
        Dim m As Map
        m = Record.Get(i)
        If m.Get("badword") = "true" Then
            Continue
        End If
        
        Dim clr As Paint = fx.Colors.Transparent 'fx.Colors.ARGB(20,Rnd(100,200),Rnd(100,200),Rnd(100,200))
        
        Dim p As Pane
        p.Initialize("")
        p.PrefWidth = CustomListView_record.AsView.Width
        p.PrefHeight = 50
        
        Dim str As String = m.Get("ms_gpt_01_04").As(String).Replace(CRLF, "").ToUpperCase.Trim
        
        Dim lb As Label
        lb.Initialize("")
        lb.Text = str
        lb.Tag=m
        
        p.AddNode(lb,0,0,p.PrefWidth,50)
        
        lb.PrefHeight = 50
        lb.Alignment = "CENTER"
        lb.TextColor = fx.Colors.White
        lb.WrapText = True
        CSSUtils.SetBackgroundColor(lb,clr)
        
        CustomListView_record.Add(p,p)
        CustomListView_record.Refresh
        
        Dim p As Pane
        p.Initialize("")
        p.PrefWidth = CustomListView_record.AsView.Width
        p.PrefHeight = 50
        
        Dim str As String = m.Get("ms_gpt_01_05").As(String).Replace(CRLF, "").ToLowerCase.Trim
        
        Dim lb As Label
        lb.Initialize("")
        lb.Text = str & CRLF & CRLF
        lb.Tag=m
        lb.PrefHeight = 50
        
        p.AddNode(lb,10,0,p.PrefWidth-20,p.PrefHeight)
        
        lb.Alignment = "CENTER"
        lb.TextColor = fx.Colors.ARGB(255,79,197,79)
        lb.TextSize = 16
        lb.WrapText = True
        CSSUtils.SetBackgroundColor(lb,clr)
        lb.As(JavaObject).RunMethod("setTextAlignment", Array("CENTER"))
    
        CustomListView_record.Add(p,p)
        CustomListView_record.Refresh
        
    Next
    
End Sub


1682070827494.png
 

ivanomonti

Expert
Licensed User
Longtime User
Hai risolto anche usato il metodo Add anziché AddTextItem (ottima scelta).

E il testo, così, fa schifo 🤣

Mai allineare testo su più righe al centro; diventa meno leggibile e più fastidioso (regola generale).
il centrato e centrato, non puoi partire con il centrato per poi andare con Left... io non lo accetterei, lo vedo come un errore totale, si ho cercato di capire come funziona questa cvl che a mio dire la trovo strana davvero, cmq Grazie anche a te @LucaMs
 
Top