ListView SecondLabel in multiple lines

nad

Active Member
Licensed User
Longtime User
Hello,

If i add a large text to a ListView1.TwoLinesAndBitmap.SecondLabel how can i do so it continues in multiple lines.
Now i add a couple words to the first label and that is ok. But i want to add a much longer text to the secondlabel but as it gets to the right of the screen the text dissapears, it does not continue below in multiple lines.


ListView1.FastScrollEnabled=True
ListView1.TwoLinesAndBitmap.ItemHeight = 70dip
ListView1.TwoLinesAndBitmap.Label.Top=1dip
ListView1.TwoLinesAndBitmap.Label.TextSize = 15
ListView1.TwoLinesAndBitmap.Label.Width=Listview1.Width-ListView1.TwoLinesAndBitmap.ImageView.Width
ListView1.TwoLinesAndBitmap.Label.TextColor = Colors.Yellow
ListView1.TwoLinesAndBitmap.Label.Gravity = Gravity.LEFT

ListView1.TwoLinesAndBitmap.Label.Height=20dip
ListView1.TwoLinesAndBitmap.SecondLabel.Height=50dip
ListView1.TwoLinesAndBitmap.SecondLabel.Top=21dip
ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 12
ListView1.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.White
ListView1.TwoLinesAndBitmap.SecondLabel.Gravity = Gravity.LEFT


Bitmap1.InitializeSample(File.DirAssets,"M-icon.png" ,50dip,50dip)

For i = 0 To Bitmaps.Size-1
Log("Bitmaps.Get("&i&"):"&Bitmaps.Get(i))
ListView1.AddTwoLinesAndBitmap(N.Get(i),N2.Get(i),Bitmap1)
Next


If N2.Get(i) is a text long enough it won't display completely just the first line. Hope you understand me with my poor english.

Thanks and best regards,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim lv As ListView
   lv.Initialize("")
   lv.TwoLinesLayout.ItemHeight = 100dip
   lv.TwoLinesLayout.SecondLabel.Height = 80dip
   lv.AddTwoLines("asdasd", "sd jflksdj flks djflksd jflksd fjlskd jflksd fjlskd fjlksdjf lksdfj ")
   lv.AddTwoLines("asdasd", "sd jflksdj flks djflksd jflksd fjlskd jflksd fjlskd fjlksdjf lksdfj ")
   lv.AddTwoLines("asdasd", "sd jflksdj flks djflksd jflksd fjlskd jflksd fjlskd fjlksdjf lksdfj ")
   Activity.AddView(lv, 0, 0, 300dip, 500dip)
End Sub

SS-2011-10-09_09.16.14.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@nad,
you must also add this line in your code:
B4X:
[SIZE=2][FONT=Courier New][SIZE=2][FONT=Courier New]ListView1.TwoLinesAndBitmap.SecondLabel.Width = Listview1.Width - ListView1.TwoLinesAndBitmap.ImageView.Width[/FONT][/SIZE][/FONT][/SIZE]
In your case you didn't see the second line for two reasons.
- The SecondLabel.Width was too wide.
- The text was too short for yout SecondLabel.Width.

Limiting the SecondLabel.Width with the line above your code will work OK.

Best regards.
 
Upvote 0

nad

Active Member
Licensed User
Longtime User
That worked perfectly!!.

Thanks a lot Erel and Klaus. I have been trying long time and couldn't see it

Cheers.
 
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Hello

I have a similar issue to this which seems to be related to the version of Android.

I'm trying to get a listview where the text in the secondlabel appears on more than one line.

The screenshot was the result of the following code:
B4X:
ListViewMain.Initialize("ListViewMain")

ListViewMain.TwoLinesAndBitmap.ItemHeight = 120dip
ListViewMain.TwoLinesAndBitmap.Label.Height = 30dip
ListViewMain.TwoLinesAndBitmap.SecondLabel.Height = 90dip
ListViewMain.TwoLinesAndBitmap.SecondLabel.Color = Colors.White
ListViewMain.TwoLinesAndBitmap.SecondLabel.Width = 180dip
      
ListViewMain.AddTwoLinesAndBitmap("Title 1", "This text goes on and on and doesn't wrap.", LoadBitmap(File.DirAssets, "dotgreen.png"))
ListViewMain.AddTwoLinesAndBitmap("Title 2", "The second line doesn't"&CRLF&"appear!", LoadBitmap(File.DirAssets, "dotgreen.png"))
   
Activity.AddView(ListViewMain, 0, 0, Activity.Width, Activity.Height)

The listvew appears correctly on a phone running an older version of Android but not in the emulator (Android 2.3.3) or on my Galaxy SII (Android 2.3.5).

Has anyone else seen this issue? Is there a workaround for it?

Regards

Joe
 

Attachments

  • ListViewIssue.png
    ListViewIssue.png
    18.5 KB · Views: 480
Upvote 0

JdV

Active Member
Licensed User
Longtime User
Annoyingly, it seems to work OK in an Android 2.2 emulator too!
 

Attachments

  • ListViewIssue2.2.png
    ListViewIssue2.2.png
    18.6 KB · Views: 324
Upvote 0
Top