B4J Question CustomListView - Textsize and xui.CreateDefaultBoldFont

Elric

Well-Known Member
Licensed User
Hello everybody!

I'd like to manage the text in the clv panel.

No problem to change the Textcolor.
B4X:
clv1.GetPanel(0).GetView(0).TextColor = xui.Color_Red

2 problems:

Problem no. 1
I cannot manage Textsize and xui.CreateDefaultBoldFont.

This code doesn't work:
B4X:
clv1.GetPanel(0).GetView(0).Font = xui.CreateDefaultBoldFont(clv1.GetPanel(0).GetView(0).TextSize)
    clv1.GetPanel(0).GetView(0).TextSize = 50
This is quite strange just because Textcolor does it...

The only solution seems
B4X:
clv1.GetPanel(0).GetView(0).As(Node).Style = ""
. With this command Textsize and xui.CreateDefaultBoldFont works.

Problem no. 2
If the only solution is the above, how I can reset the height of the single row to fit automatically with the text lenght?

In particular, sometimes when normal text will set bold may happens that a new line is needed.

How to solve it?

Thank you!
 

Attachments

  • CustomListViewTextSizeandBoldfont.zip
    12 KB · Views: 93

Erel

B4X founder
Staff member
Licensed User
Longtime User
If all items use the same text setting then you should do it with the designer. Simply set the text properties of the CLV.

If you want to add items with different settings then modify CLV.DesignerLabel before you add the item with CLV.AddTextItem:
B4X:
CLV.DesignerLabel.Style = ""
CLV.DesignerLabel.As(B4XView).Font = ...
CLV.AddTextItem(...)
 
Upvote 0

Elric

Well-Known Member
Licensed User
Thank you!

I'd like to change it at run-time. I'm working on a "choose the right answear" so: for the first question I'd like to highlight the correct answear and, then, go to second question, I'd like to reset going back to plain text and, again, highlight the right anwear and, then, go to third question and so go on.

Maybe it's more simple, use one clv for one answear?
 
Upvote 0

Elric

Well-Known Member
Licensed User
Thank you! (sorry for late answear!)
Another option is to use CSBuilder, however the text measurement will not be 100% accurate.
I knew that CSBuilder was not on B4J... was it?

You can change it at runtime. Simply set the DesignerLabel font before you add the item.
If I understood correctly, in the case I've already add the item, to change such item I need to remove it and add it again?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I knew that CSBuilder was not on B4J... was it?
No.

If I understood correctly, in the case I've already add the item, to change such item I need to remove it and add it again?
No. Either set the style to "" or set the style of DesignerLabel to "" before you add the items.
 
Upvote 0

Elric

Well-Known Member
Licensed User
Thank you!

So, first of all:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    '...[other code]...
    clv1.DesignerLabel.Style = ""
    clv2.DesignerLabel.Style = ""
    '...[other code]...
End Sub

Then add items:
B4X:
    '...[other code]...
    clv1.AddTextItem(strString, strString)
    clv1.AddTextItem(strString, strString)
    clv1.AddTextItem(strString, strString)
    '...[other code]...

Then I can change them:
B4X:
    '...[other code]...
    clv1.GetPanel(0).GetView(0).TextColor = xui.Color_Red
    clv1.GetPanel(0).GetView(0).TextSize = 20
    clv1.GetPanel(0).GetView(0).Font = xui.CreateDefaultBoldFont(20)
    '...[other code]...

I've used
B4X:
clv1.GetPanel(0).GetView(0).Font
instead of
B4X:
CLV.DesignerLabel.As(B4XView).Font
to change only one item. I think is correct, doesn't it?

Here attached my example.

I've a question about the reset panel height in CLV and why does work properly neither with plain text nor with bold text but I think I should open a new thread about that.
 

Attachments

  • CustomListViewTextSizeandBoldfont.zip
    13.4 KB · Views: 105
Last edited:
Upvote 0
Top