I want to load data from a text file (test.txt) to a listviews..
Text file data will be for e.g.
12343
2345
23678
897345
34536
Each data in text file should be as loaded as different items in listview.
B4X:
Sub ReadTextReader
Dim TextRd As TextReader
TextRd .Initialize(File.OpenInput(File.DirRootExternal, "test.txt"))
Dim line As String
line = TextRd .ReadLine
Do While line <> Null
line = TextRd .ReadLine
Loop
ListView1.AddSingleLine(line)
TextRd .Close
End Sub
i tried the above code but giving me null pointer error. anyone please help me..
Sub ReadTextReader
Dim TextRd As TextReader
TextRd.Initialize(File.OpenInput(File.DirRootExternal, "test.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
I could imagine that this solution will also crash when the textfile is empty.
Leave out the two lines before the Do-While-Clause and this should be fixed.
The above is more correct, as you read a line first, and only run the loop if it is not null. Then the loop adds the line to the listview and gets next line. This continues until line is null.