Android Question B4A scrolling text window

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
Several times now over the past few years I have needed a scrolling text window.

Think of the old 1980s and 1990s video display terminals where you have 25 lines by 80 characters of text. New text is appended at the bottom and old text scrolls off the top screen.

Each of the lines of text could be short, terminated by a CRLF, or they could be long and wraparound several physical lines.

I am currently using an EditText control with a list in the background holding the individual lines of text. This has the problem of not knowing exactly how many lines can fit in the EditText control on the screen – remember lines can be short or they can be long and wraparound to several physical display lines.

I'm obviously not thinking of the problem correctly. How would others approach this problem?

I kind of think ListViews or ScrollViews won't work because of the short line/long line wraparound problem. How would you approach this?

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks.

I chose an EditText rather than a Label because the person will need to enter text via the keyboard.

My main question is about handling scrolling/knowing when to delete old text.

Suppose you have three lines of text: A really long line of text that wraps around to the next line in the control, a short line, and another really long line of text that wraps around. When displaying this text it will require five lines within the control, but suppose the control is only tall enough support 4 lines of text. I don't want to have a scrollview, make the control larger, and scroll the control. I want to remove the first long line of text and only display the last three lines – similar to old video display terminals.

Erel has a function, I believe it's in StringUtils, that returns the height required to display multi-line text.

I adjust the number of lines of text based on how many lines will fit into the control. If the number of lines of text height is greater than the height of the control, I delete the oldest lines of text until it fits. I haven't had 100% success using this algorithm.

It seems so easy on paper :D. Any suggestions for doing something similar to this?
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I believe that in Erel's code snippet above, the following line :
B4X:
If EditText.Text > 10000 Then EditText.Text = EditText.Substring(9000)
should be :
B4X:
If EditText.Text.Length > 10000 Then EditText1.Text = EditText1.Text.Substring(9000)
 
Upvote 0
Top