Listview and sql

fanfalveto

Active Member
Licensed User
Longtime User
I have a database and i fill a listview with it
B4X:
Sub ListViewFill   
   ListView1.Clear
   cur = SQL1.ExecQuery(sqltxt)
   Dim ar As String
   For i = 0 To cur.RowCount - 1
      cur.Position = i
      If cur.GetString("Color1").Contains(" ") Then
      ar=cur.GetString("Color1").Replace(" ","")
      End If
      ListView1.AddSingleLine(ar&" "&cur.GetString("Color2")&"    "&cur.GetString("Color3")&"    "&cur.GetString("Descripcion")&"    "&cur.GetString("Data")&"    "&cur.GetString("Fil3")&" "&cur.GetString("Descr2")&"   "&"AC,BG?")
   Next
End Sub
please, how I can assign a specific space for each item i add to a listview line? so that all items are under each other without being displaced along the length of the above?
now thats happens:
B4X:
a    linea1    averquepasa
aa    linea1    mal
1    dos    tres
and i want something like this.
B4X:
a      linea1     averquepasa
aa     linea1     mal
1      dos        tres
Thank you very much.
Ahh,this is the listview init
B4X:
Sub ListViewInit
   ListView1.SingleLineLayout.ItemHeight = 40dip
   ListView1.SingleLineLayout.Label.Left = 0
   ListView1.SingleLineLayout.Label.Width = 100%x
   ListView1.SingleLineLayout.Label.Height = 40dip
   ListView1.SingleLineLayout.Label.Gravity = Gravity.CENTER_VERTICAL
   ListView1.SingleLineLayout.Label.Color = Colors.White
   ListView1.SingleLineLayout.Label.TextSize = 15
     ListView1.SingleLineLayout.Label.TextColor = Colors.Black
   ListView1.FastScrollEnabled = True
End Sub
 

fatman

Active Member
Licensed User
Longtime User
Hi fanfalveto,

have you tried using a monospaced font? Something like this:

ListView1.SingleLineLayout.Label.Typeface = Typeface.MONOSPACE

Helps in many cases like that ;-)

Fatman
 
Upvote 0

fatman

Active Member
Licensed User
Longtime User
Hi fanfalveto,

monospaced font may not so helpful in your case... Here´s a different approach: for example take the "a" add 10 spaces, shorten the result to let´s say to 10 letters add this to another variable. Take "linea1" add 10 spaces, shorten the result and so on.

Fatman
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
this is a combination of both fatman's answers, but unless you can predict your largest data's width/lenght it could fail. Plus not the best display font.
B4X:
Dim strA() As String   :strA = Array As String("a", "aa", "1")
Dim strB()As String    : strB = Array As String("linea1", "linea1", "dos")
Dim strC() As String    : strC = Array As String("1", "dos", "tres")

ListView1.SingleLineLayout.Label.Typeface = Typeface.MONOSPACE
   
   For i = 0 To 2
      ListView1.AddSingleLine(Pad(strA(i)) & Pad(strB(i)) & Pad(strC(i)))
   Next
End Sub

Sub Pad(str As String) As String
   
   Dim TargetLen As Int  :TargetLen = 10
   
   Do Until str.Length = TargetLen
      str = str & " "
   Loop
   Return str
   
End Sub

Another option might be CustomListView ,loading 3 Labels on each row ..

Cheers mj
 
Upvote 0

fatman

Active Member
Licensed User
Longtime User
Hi,

mangojack is right.
Maybe you´ll have a look at Grid Library by Stefanobusetto. I havent tested it yet but it looks promising.

Fatman
 
Upvote 0
Top