Android Question More lines on a label or on a editText view

Tjitte Dijkstra

Member
Licensed User
Longtime User
I am working on an educational game. During the game some mistakes are made. After some time the user wants to know what kind of mistakes were made and does so by clicking the scoreboard. I then present an EditText (single line property = false) and I try to show three or more mistakes, each on their own line.
My source:

'There is a global variable called Mistakes as list (Of strings)
'Score_INFO is an EditText (outlined to the left and the top)

B4X:
Sub scoreboard_Click
Dim Mistake As String 'In the list Mistakes every mistake is an individual string
Dim nr As Int
    Score_INFO.SingleLine = False 'to make sure that more lines are used
    For nr = 0 To Mistakes.Size-1
    Mistake = Mistakes.Get(nr)
    Score_INFO.Text = Mistake & CRLF
    Next
End Sub
But, what happens? Only the last Mistake from the list Mistakes is shown and earlier mistakes are overwritten. (By the way: the same happens if I use a label in stead of an EditText.)
What is the mistake I make?
TD
 

stevel05

Expert
Licensed User
Longtime User
Try:

B4X:
Score_INFO.Text = Score_INFO.Text  & Mistake & CRLF

You need to copy the existing contents of the edittext field too, or as you say, it get's overwritten.
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Unless you need it for something else you really don't need to define 'Mistake'. Try this:

B4X:
Sub scoreboard_Click
    Dim nr As Int
    Score_INFO.SingleLine = False 'to make sure that more lines are used
    Score_INFO.Text = ""   ' To ensure this starts out empty
    For nr = 0 To Mistakes.Size-1
       Score_INFO.Text = Score_INFO.Text & Mistakes.Get(nr) & CRLF
    Next
End Sub
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
Hi all,

Thank you so much. Debugging is standard in my work and I saw the variables change, but only after the advice of Steve, my attempts reached their goal. (Amazing that nowhere in Seagrave nor in the Tutorials the solution could be found.)
Thanks Tom for skipping the Mistake variable and emptying INFO.text.
For now this is enough.
Tjitte Dijkstra (beginner in B4A, but experienced in Pascal & Delphi)
 
Upvote 0
Top