extract from text file content.

fifiddu70

Well-Known Member
Licensed User
Longtime User
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?

example:
txt file.

one
two
three
four


listview?
 

fifiddu70

Well-Known Member
Licensed User
Longtime User
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
 

Attachments

  • po.png
    49.6 KB · Views: 207
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
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
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
hello fifiddu70

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

Cheers mj
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…