Android Question can this be done with b4a??

ilan

Expert
Licensed User
Longtime User
B4X:
VB.NET program that uses padding String

Module Module1
    Sub Main()
    ' Format String.
    Dim format As String = "{0,-10} {1,10}"

    ' Construct lines.
    Dim line1 As String = String.Format(format, 100, 5)
    Dim line2 As String = String.Format(format, "Carrot", "Giraffe")
    Dim line3 As String = String.Format(format, True, False)

    ' Print them.
    Console.WriteLine(line1)
    Console.WriteLine(line2)
    Console.WriteLine(line3)
    End Sub
End Module

B4X:
Output

100                 5
Carrot        Giraffe
True            False

as you can see the text is formated perfectly, first string of first line is to the left and second srting to the right
and all 3 lines are formated the same.

i would liek to do this with a LV singleline label.text, is this possible?
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Yes, but you'll have to implement your own alignment methods (it's not hard, just choose a column width and add ColumnWidth-String.Length spaces with a StringBuilder before adding your String to the StringBuilder). Make sure to use a monospaced font in your View.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Yes, but you'll have to implement your own alignment methods (it's not hard, just choose a column width and add ColumnWidth-String.Length spaces with a StringBuilder before adding your String to the StringBuilder). Make sure to use a monospaced font in your View.

thanx a lot i allready figured out that what i was missing was the monospaced font, the problem is i am using hebrew font and i had no monospace font in hebrew thatswhy i did not get the result i wanted, but now i will try with a font i found (miriam_fixed) and hope it will work!

thanx anyway :)

EDIT: yes it is working, b4a is great!
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
As you know, you could use CustomListView, creating an item with two labels (so you can choose any font type and also different fonts for the labels).

its funny that you are posting this answer because i am using your code that also looks much better then mine and also solved my problem.

btw: i am using CLV a lot in my apps, but i wanted to use something simple. CLV need to much coding... :confused:
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
why not using 2 labels with one aligned left and the other to the right ?

then you can use any proportional/condensed font.

they can even completely overlap (x,y,width,height the same) each other to cover long strings.

if it is for the log panel you use a terminal/monospace font and add spaces of the full line - (1st +2nd string lenght)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
why not using 2 labels with one aligned left and the other to the right ?

then you can use any proportional/condensed font.

they can even completely overlap (x,y,width,height the same) each other to cover long strings.

if it is for the log panel you use a terminal/monospace font and add spaces of the full line - (1st +2nd string lenght)

its a listview, what u r suggesting would work with CLV but i wanted to use a listview...
 
Upvote 0
Top