ListView AddTwoLines Not displaying

LittleEddie

Member
Licensed User
Longtime User
I'm display a SQLite into a ListView but the display is adding a extra linefeed whenever it wants to. I'm using AddTwoLines or AddTwoLinesAndBitmap, both are doing this.

listview1.png


Listview2.png


listview3.png


All I did was scroll the list up and down, it's always different. There are over 1200 items in the SQL but sometimes it will do it will only 20 or so also.

I've try with and without a bitmap.

It only seems to do this in portrait mode, Landscape is correct.

My Current code, with bitmap, 100x100 transparent, one with star,

B4X:
Sub UpdateSongs
   lvSongs.Clear
   Dim Cursor1 As Cursor
   Dim Bitmap1 As Bitmap
   Dim BitmapEmpty As Bitmap
   Bitmap1.Initialize(File.DirAssets, "Star2.png")
   BitmapEmpty.Initialize(File.DirAssets, "Empty100x100.png")
   'This moves the Bitmap to the Right side of the screen
   lvSongs.TwoLinesAndBitmap.ImageView.Left = lvSongs.Width - (Bitmap1.Width / 1.5)
   lvSongs.TwoLinesAndBitmap.Label.Left = 0
   lvSongs.TwoLinesAndBitmap.SecondLabel.Left = 0
   'lvSongs.TwoLinesAndBitmap.Label.Width = lvSongs.Width - Bitmap1.Width
   'lvSongs.TwoLinesAndBitmap.SecondLabel.Width = lvSongs.Width - Bitmap1.Width
   If CurrentArtist <> "" Then
      Cursor1 = main.SQL1.ExecQuery("SELECT DISTINCT * FROM main WHERE artist = " & QUOTE & CurrentArtist & QUOTE & " ORDER BY title;")
      For i = 0 To Cursor1.RowCount - 1
         Cursor1.Position = i
         If Cursor1.GetInt("fav") = 0 Then
            lvSongs.AddTwoLinesAndBitmap(Cursor1.GetString("title"), cursor1.GetString("artist"), BitmapEmpty)
         Else
            lvSongs.AddTwoLinesAndBitmap(Cursor1.GetString("title"), cursor1.GetString("artist"), Bitmap1)
         End If
      Next      
   Else
      Cursor1 = main.SQL1.ExecQuery("SELECT * FROM main ORDER BY title;")
      For i = 0 To Cursor1.RowCount - 1
         Cursor1.Position = i
         If Cursor1.GetInt("fav") = 0 Then
            lvSongs.AddTwoLinesAndBitmap(Cursor1.GetString("title"), cursor1.GetString("artist"), BitmapEmpty)
         Else
            lvSongs.AddTwoLinesAndBitmap(Cursor1.GetString("title"), cursor1.GetString("artist"), Bitmap1)
         End If
      Next
   End If
   Cursor1.Close
   
End Sub

Any Ideas

Little Eddie
 

LittleEddie

Member
Licensed User
Longtime User
I tried it on two different phones, on both it's bad in protrait mode and fine in Landscape

I also tried it with Fast Scroll both on and off

Little Eddit
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
No, that's the first thing I checked.

Again all I did was scroll the ListView up and down and a different one was messed up.
No orientation change!
No Code was ran!

in the first ScreenShot the 1st, 7th and 8th item show has extra spaces
Scroll up a 100+- records and back to the same spot and
items 2, 4 and 6 are messed up
Scroll down a few 100+- records and back to the same spot and
items 5, 6 and 8 are messed up.

some of the data
"STUART, MARTY","IF I GIVE MY SOUL"
"STUART, MARTY","LITTLE THINGS"
"STUART, MARTY","LOVE & LUCK"
....
"TUCKER, TANYA","JUST ANOTHER LOVE"
"TUCKER, TANYA","LITTLE THINGS"
"TUCKER, TANYA","LIZZIE & THE RAINMAN"

Imported from .csv to SQLite


Little Eddie
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
Here's the code for the tranfer from .csv to Sqlite

B4X:
Sub CsvSongBook_StreamFinish (Success As Boolean, TaskId As Int)
   If Success = False Then                'This takes the .CSV file we just downloaded and puts it into a SQLite database
      Msgbox("Error SongBook_StreamFinished Failed", "SongBook")
      'need to exit here, no need to do the rest****************************************************************************************
   End If
   Dim List1 As List
   Dim String1() As String
   'Get a list of Favorites from 'main' and put it in a new table for later use
   SQL1.ExecNonQuery("DROP TABLE IF EXISTS favor")
   SQL1.ExecNonQuery("CREATE TABLE favor AS SELECT * FROM main WHERE fav = '1'")
   
   List1 = StrUtl.LoadCSV(File.DirInternalCache, "SongBook.csv", ",")'This will take the .csv file and read it into a list, 
                                                           'Each Row in file will be Array of Strings, one for each column
   SQL1.ExecNonQuery("DROP TABLE IF EXISTS main") 'delete old song list
   SQL1.ExecNonQuery("CREATE TABLE main (artist TEXT, title TEXT, fav INTEGER)")'create a new table
   SQL1.BeginTransaction
   Try
      For i = 0 To List1.Size - 1
         String1 = List1.Get(i) ' Get the Array of Strings from the list.
         SQL1.ExecNonQuery("INSERT INTO main VALUES(" & QUOTE & String1(0) & QUOTE & ", " & QUOTE & String1(1) & QUOTE & ", 0);")
      Next
      SQL1.TransactionSuccessful
   Catch
      Log(LastException.Message)
      Msgbox(LastException.Message, "Error")
   End Try
   SQL1.EndTransaction 'save all, if no error messages we are good
   ' Update the new database with our Favorites list
   Dim Cursor1 As Cursor
   Cursor1 = SQL1.ExecQuery("SELECT * FROM favor WHERE fav = 1")
   For i = 0 To Cursor1.RowCount - 1   '"UPDATE main SET fav='1' WHERE title = " & QUOTE & Value & QUOTE & ";")
      Cursor1.Position = i
      SQL1.ExecNonQuery("UPDATE main SET fav = '1' WHERE artist = " & QUOTE & Cursor1.GetString("artist") & QUOTE & " AND title = " & QUOTE & Cursor1.GetString("title") & QUOTE & ";")
   Next
   SQL1.ExecNonQuery("DROP TABLE IF EXISTS favor")  'no need to keep this
   Cursor1.Close
   ProgressDialogHide
End Sub

But I don't think the problems is here, if it was the problem would not be random in the ListView

LittleEddie
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
it's 5 meg with the files
Send me a email at edward at mvjoybells dot com
and i will send it to you.

I zipped it, moved it unzipped, loaded it into b4a and ran it

Ed
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
OK, here's what I think I've found and I need someone to check it out.

In ListView, if the Text in any Label is Longer then a Single Line it will change the Label to MultiLine, and that would mess it up.

It looks to me that the ListView is like 8(# the user sees on screen) labels with the data scrolling over them. if one is too long it will go to MultiLine, which is good, I guess, But now Every 8th Label is Multiline even if the Text is has to display is not.

Ed

I limited the length of text to 26 char's and the problem when away, now it the complete name is not displayed the user can click on it to get a msgbox for the full title.
 
Upvote 0

WZSun

Member
Licensed User
Longtime User
Hi,
I noticed it in my own project. It took me a while before I found out the reason. It is due to the length of the text string that extend beyond the 'width of the listview'.

Here's what I did:
Check the length of the text string. If it's longer than certain length, I would replace it with a "...". This way, there would not be any text string longer than the allowable length.

Rgds
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Ed,
I tested your program and found the 'strange' behaviour too !

I tested if there are extra LF or CR characters, there are none.

It is strange because the same short text like "1901" is sometimes displayed OK (single line) and sometimes in two lines, only depending on he scrolling.

As a workaround you can add following lines to make shure that the labels show the first line.
B4X:
[FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]lvSongs.TwoLinesAndBitmap.Label.Gravity=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Gravity[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].TOP[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]lvSongs.TwoLinesAndBitmap.SecondLabel.Gravity=[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Gravity[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].TOP[/SIZE][/FONT][/SIZE][/FONT]

Best regards.
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
Well, Gravity.TOP didn't work.

Canvas.StringLength I havn't tried but I think it would take too much time on a long list.

Ed
 
Upvote 0

LittleEddie

Member
Licensed User
Longtime User
Here's what I ended up doing.

In Activity_Resume I put

If Activity.Width > Activity.Height Then
Orient = 1 'landscape
Else
Orient = 0 'Portrait
End If

In my SQLite I added a new column ShortTitle where every item had only a max of 27 Chars. I used this number based on my Font size.

Then If the phone was in Portrait mode I used the Short Title, landscape I used the Long Title. a simple if/then/else

the Longest list has 17,000 items so I don't what to check every items length and shorten it. That would just take too much time. and putting in two lines with bitmap takes long enough.

Ed

Ed
 
Upvote 0
Top