Italian [B4J] CustomListView1 - lettura contenuto TextField1

MARCO C.

Active Member
Licensed User
Buonasera,
in riferimento ad un progetto esempio sul CustomListView1 che ho recuperato in un post, vorrei sapere come prendere i valori
inseriti nei vari campi TextField1, per esempio, tramite un ciclo FOR , in un vettore o list
valore(1) = "Text 10"
valore(2) = "Text 20"
valore(3) = "Text 30"
valore(4) = "Text 4"
.
.
custom.png


B4X:
Sub Process_Globals

Private fx As JFX

Private MainForm As Form

Private xui As XUI



Private CustomListView1 As CustomListView

Private CheckBox1 As CheckBox

Private Label1 As Label

Private Button1 As Button

Private lblValore As Label

Private lblTestoLabel As Label

Private TextField1 As TextField

End Sub



Sub AppStart (Form1 As Form, Args() As String)

MainForm = Form1

MainForm.RootPane.LoadLayout("layMain") 'Load the layout file.

MainForm.Show

RiempiXCLV

End Sub



'Return true to allow the default exceptions handler to handle the uncaught exception.

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean

Return True

End Sub





Sub RiempiXCLV

For i = 1 To 20

CustomListView1.Add(CreaItem(i), i * 10)

Next

End Sub



Sub CreaItem(Indice As Int) As B4XView

Dim pnlNew As B4XView

pnlNew = xui.CreatePanel("")

pnlNew.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 45dip)

pnlNew.LoadLayout("layXCLVItem")

Label1.Text = "Elemento #: " & Indice

If Rnd(0, 2) = 1 Then

CheckBox1.Checked = True

Else

CheckBox1.Checked = False

End If

Button1.Text = "Button " & Indice

TextField1.Text = "Text " & Indice

Return pnlNew

End Sub



Sub Label1_MouseClicked (EventData As MouseEvent)

Dim lbl As Label = Sender

lbl.TextColor = fx.Colors.Red

lblTestoLabel.Text = "Testo: " & lbl.Text



' Si può ottenere il valore associato all'item

' in questo modo:

Dim Indice As Int = CustomListView1.GetItemFromView(lbl) ' va bene anche Sender

Dim Valore As Int = CustomListView1.GetValue(Indice)

Log("Valore: " & Valore)

End Sub



Sub Button1_Click

Dim btn As Button = Sender

btn.TextColor = fx.Colors.Blue

lblValore.Text = "Button: " & btn.Text

End Sub



Sub CustomListView1_ItemClick (Index As Int, Value As Object)

lblValore.Text = "Valore item: " & Value

End Sub

Grazie in anticipo
M.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Buonasera,
Ci sarebbe stato meglio un "Buongiorno", visto che erano le 11 😊 (dimostra quanto siamo sfasati noi programmatori)

Quando pubblichi codice sorgente, usa il menu:
1678624301387.png


Adesso puoi "correggere" quello già pubblicato, premettendo:
CODE=b4x

e concludendolo con:
/CODE

(entrambe le righe tra parentesi quadre, cosa che non ho potuto fare altrimenti sarebbero state interpretate come "comandi" per l'editor)

Meglio ancora se tu potessi allegare il progetto.

La risposta effettiva la scriverò tra non molto.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
B4X:
Private Sub GetTexts As List
    Dim lstResult As List
    lstResult.Initialize
   
    For i = 0 To CustomListView1.Size - 1
        Dim pnl As B4XView = CustomListView1.GetPanel(i)
        Dim tf As TextField = pnl.GetView(2) '<---
        lstResult.Add(tf.Text)
    Next
   
    Return lstResult
End Sub

Cambia l'indice in pnl.GetView(2) se la tua TextField non è la terza view nel layout layXCLVItem (l'ordine lo vedi nella "Views Tree", a sinistra nel Designer)

Nota: all'interno del ciclo potresti anche sostituire le 3 righe con una unica:
B4X:
    For i = 0 To CustomListView1.Size - 1
        lstResult.Add(CustomListView1.GetPanel(i).GetView(2).Text)
    Next
anche se così sarebbe un po' meno leggibile (e gestibile, in caso di modifiche)
 

MARCO C.

Active Member
Licensed User
Perdono @LucaMs , esiste l'inverso del Get ??

B4X:
Dim tf As TextField = pnl.GetView(3)

tipo set ... write .. !!
ho necessità di sovrascrivere sul TextField1 . Tra le varie proprietà non trovo nulla di appropriato
Grazie
 
Top