Android Question Alignment / Formatting of several strings in one line

h725

Active Member
Licensed User
Longtime User
Hello Community !

I have the following question:
I have e.g. quantity , description and price.

How can I format this information in a way that I can
get something like that (I have a maximal number of characters in one line):

alignment.png


Thank you very much in advance

Kind regards
h725
 

Mahares

Expert
Licensed User
Longtime User
Your best bet is to put the data in a CSV (text file) where the items are separated by commas or any other character and use the Tableview class by @klaus to display the data with great flexibility. Here is the link:
https://www.b4x.com/android/forum/threads/class-flexible-table.30649/
His latest class is version 2 where there is an example in post #1. Alternatively, you can put the data in a SQLite database table and view it using the same class.
Your text file can be as such using a semi-colon as a delimiter:
2;Monitor;100,00
10;VGA Cable;20,00
1;Stand;9,00
 
Upvote 0

h725

Active Member
Licensed User
Longtime User
The data is coming from a table but I need it formatted as string
in the way that the alignment of (e.g.) the description is exactly
underneath the other. Please have a look:
alignment2.jpg

Also the comma of the price should be in this kind of format.
I know exacty how many characters are allowed in one line. So
maybe this can be useful. I was thinking of 3 seperated strings with
fixed length, in which I can put the information and align the information.
 
Upvote 0

h725

Active Member
Licensed User
Longtime User
Hello community.
After searching on the b4x forum, I found the following entry:

https://www.b4x.com/android/forum/threads/add-spaces.25414/

I looked at the snippet and changed it a little bit and got a solution which works for me:

B4X:
Sub SpaceRight(retStr As String,HM As Int) As String 
 
    If retStr.length < HM Then
   Do While retStr.Length < HM
      retStr =  retStr & " "
   Loop
   End If
   If retStr.Length = HM Then
       retStr =  retStr
End If
If retStr.Length > HM Then
    retStr = retStr.SubString2(0,HM)
End If
   Return retStr
 
End Sub
Sub SpaceLeft(retStr As String, HM As Int) As String 
       If retStr.length < HM Then 
   Do While retStr.Length < HM
      retStr = " " & retStr
   Loop
   End If
   If retStr.Length = HM Then
       retStr =  retStr
End If
If retStr.Length > HM Then
    retStr = retStr.SubString2(0,HM)
End If
   Return retStr
 
End Sub
 
Last edited:
Upvote 0
Top