Hello everyone, I would like to extract from a text file content
and display it on a listview
each line of text should be displayed in a row in the listview
I would also like that at some point in the text does not appear the rest of the content, someone tell me how to do?
resolved in this metod
one problem in listview the read line is show as from photo.
for eliminate the spaces?
B4X:
Sub ReadTextReader
Dim TextRd As TextReader
TextRd.Initialize(File.OpenInput(File.DirRootExternal,txtordern.Text & ".txt"))
ListView1.Clear
Dim line As String
line = TextRd.ReadLine
ListView1.AddSingleLine(line)
Do While line <> Null
line = TextRd.ReadLine
ListView1.AddSingleLine(line)
Loop
TextRd.Close
End Sub
resolved, i change: ListView1.AddSingleLine(Line ) in
ListView1.AddSingleLine(TextRd.ReadLine )
B4X:
Sub ReadTextReader
Dim TextRd As TextReader
TextRd.Initialize(File.OpenInput(File.DirRootExternal,txtordern.Text & ".txt"))
ListView1.Clear
Dim line As String
line = TextRd.ReadLine
ListView1.AddSingleLine(line)
Do While line <> Null
line = TextRd.ReadLine
ListView1.AddSingleLine(TextRd.ReadLine )
Loop
TextRd.Close
End Sub
From what I see in your last post you are reading every line ,but only adding every second line to the list.
If you don't want to add empty lines maybe this is better suited.
B4X:
Sub ReadTextReader
Dim TextRd As TextReader
TextRd.Initialize(File.OpenInput(File.DirRootExternal,txtordern.Text & ".txt"))
ListView1.Clear
Dim line As String
Do While line <> Null
line = TextRd.ReadLine
If line = Null Then Exit
If line <> "" Then
ListView1.AddSingleLine(line)
End If
Loop
TextRd.Close
End Sub