Android Question Is there a sample program for displaying textlines from a file?

Similar threads

B4A Tutorial LoadBitmap / LoadBitmapResize / LoadBitmapSample
B4A Library FirebaseAdMob v1.6
B4A Library [B4X] BitmapsAsync
B4A Tutorial [B4X] Comment Links
B4A Tutorial Text files

Tjitte Dijkstra

Licensed User
I am working on an educational game. I want to give the adult users (parents / teachers) the possibility to enter some lines (e.g. tips or peptalks etc) for the new kids who work with the game.
What I need is an EditText (single line = false) and with TextWriter & TextReader I save and load it.
So far, so good, but what next?
1. Now I want to print the loaded tekst line for line on a label or something. But how?
2. Is there in the sample files some sort of a textprocessor?

Tjitte Dijkstra

Licensed User
Thank you so far.
That is the example that I found in the Wyken Seagrave guide. But then you only have it in the Log and I managed to do that already.
I want to display it on the tablet, preferably on a label.


Licensed User
I want to display it on the tablet, preferably on a label.
    Dim f As String = File.ReadString(File.DirAssets,"AbstractLayouts.txt")
  Label1.Text = f


Tjitte Dijkstra

Licensed User
Thnx again. See my code. It works for only one line and then the next line replaces the former, etc.
I want to display a lot of lines, maybe even with a scrollbar?

Sub OPEN_Click
Dim TextReader1 As TextReader
    TextReader1.Initialize(File.OpenInput(File.DirRootExternal, "Test.txt"))
    Dim line As String
    line = TextReader1.ReadLine   
    Do While line <> Null
        Log(line) 'write the line to LogCat
        line = TextReader1.ReadLine
        Label1.Text = line
End Sub


Well-Known Member
Licensed User
These will be the steps involved.
  1. Add a ScrollView to the Activity.
  2. Add a Label to the ScrollView. Use any height for the Label. We will set it correctly later.
  3. Read the contents of the text file to Label using File.ReadString (or TextReader.ReadAll)
  4. Add StringUtils library to the project and use StringUtils.MeasureMultilineTextHeight to calculate the minimum height needed to display the text you read from the file. Set this value as the Label's height.
  5. Set the ScrollView.Panel.Height to a value >= the Label's height you got in Step 4.