B4J Question [SOLVED]How to format Text Field with CRLF?

Zvi

Member
Licensed User
I am using a TextField called emailBody that I would like to format into multiple lines for a copy-paste action by user.
My code uses CRLF as follows:
B4X:
    emailBody.Text = "Payment ref:" _
                & CRLF & TAB & paymentTextF.Text _
                & CRLF & TAB & TAB _
                & CRLF & "Email:" _
                & CRLF & TAB _
                & CRLF  & tex _
                & CRLF & TAB & TAB _
                & CRLF & "DEVICE SERIAL No." _
                & CRLF & TAB _
                & CRLF & codeTextLbl.Text

But when I run the program all the text appears on one line:
Screenshot - 21_06_2023 , 13_46_13.jpg


If I use a label instead of a textfield then I can format it to multiple lines but the user can't copy the text from the label.
I also tried using a text area but then I can't format to multiple lines nor can it be copied.
Using BCText engine also doesn't allow copying of text.

How can I format the text field in my code to write multiple lines?

Any help would be greatly appreciated.
 

Daestrum

Expert
Licensed User
Longtime User
Use smart strings $" "$ and a TextArea ( TextField's I believe are single line) and TextArea's allow copy/pasting.

B4X:
    emailBody.Text = $"Payment ref:   ${paymentText.Text}
Enail :        ${theEmail.Text}
Device Serial Number:     ${codeTextLbl.Text} "$

Anything inside ${ } will have it's value inserted into the string and you don't need to use line continuation _
 
Last edited:
Upvote 0

Zvi

Member
Licensed User
Thanks Daestrum, that's useful to know and I'll use it. But it still doesn't format my text into multiple lines.
Now I see that Erel answered in a similar post "TextField is an editable field however it is a single line control." and suggested using Text Area.
I used Text Area as in this code:
B4X:
    emailTextArea.Text = $"Payment ref:   ${paymentTextF.Text} & CRLF
                    Email :        ${emailTextF.Text}  & CRLF
                    Device Serial Number:     ${codeTextLbl.Text} "$  & CRLF

Works! Thanks :)
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
If you need tabs or CRLF then you can put them into ${ } tags too

${TAB}${CRLF} will insert a Tab and CRLF into the line.
 
Upvote 0
Top