Android Question [Solved] How to refresh the CustomListView when change the textsize?

asales

Expert
Licensed User
Longtime User
I fill the customlistview with several texts using AddTextItem.

Now I put 2 buttons to increase and decrease the textsize.
This is the code from the buttons:
B4X:
clvPhrases.DesignerLabel.TextSize = IntNewTextSize
clvPhrases.Refresh    'don't work to change the text size without reload the items
I get the change in text size only if I clear the CLV and reload the items.

Is possible to change (refresh) the text size of the items show in CLV without reload?

Thanks in advance for any help.
 

PaulMeuris

Active Member
Licensed User
You are right, the refresh method doesn't work.
Here is some code that works. It uses a for loop to go over the items and set the text size.
The itemclick method emphasizes the clicked item (larger size and background yellow).
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private btnlarger As Button
    Private btnsmaller As Button
    Private clvphrases As CustomListView
    Private inttextsize As Int = 16            ' set the initial textsize!
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    For i = 0 To 4
        clvphrases.AddTextItem("text item "& i,"item" & i)
    Next
End Sub
Private Sub btnsmaller_Click
    inttextsize = inttextsize - 2
    clvphrases.DesignerLabel.TextSize = inttextsize
    For i = 0 To 4
        clvphrases.GetPanel(i).GetView(0).SetTextSizeAnimated(0,inttextsize)
    Next
    'clvphrases.Refresh    'don't work to change the text size without reload the items
End Sub
Private Sub btnlarger_Click
    inttextsize = inttextsize + 2
    clvphrases.DesignerLabel.TextSize = inttextsize
    For i = 0 To 4
        clvphrases.GetPanel(i).GetView(0).SetTextSizeAnimated(0,inttextsize)
    Next
    'clvphrases.Refresh    'don't work to change the text size without reload the items
End Sub
Private Sub clvphrases_ItemClick (Index As Int, Value As Object)
    Dim intlarge As Int = inttextsize + 8
    clvphrases.GetPanel(Index).GetView(0).SetTextSizeAnimated(0,intlarge)
    clvphrases.GetPanel(Index).GetView(0).SetColorAndBorder(xui.Color_Yellow,0,0,0)
End Sub
Happy coding!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test:
1.gif
2.gif
 

Attachments

  • clvtest.zip
    14.8 KB · Views: 71
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
view custom listview text wrap discussion post:
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Both codes works!

A third method you can add to your repertoire is using a B4XPlusMinus instead of 2 buttons:
B4X:
Sub PlusMinus_ValueChanged (Value As Object)
    SetTextItemSize(Value)
End Sub

Public Sub SetTextItemSize(tsize As Float)
    For i = 0 To clv1.Size - 1
        Dim lbl As B4XView = clv1.getPanel(i).GetView(0)
        #if B4J
        lbl.As(Label).Style = $"-fx-font-size:$1.2{tsize};"$
        #Else
        lbl.TextSize = tsize
        #End If
        lbl.TextColor = xui.Color_Black
        clv1.getPanel(i).SetColorAndBorder(xui.Color_White, 5dip, xui.Color_DarkGray, 6dip)
    Next
End Sub

1687480099913.png
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
other
2.gif

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
    B4XSeekBar1.Value = clv1.DesignerLabel.TextSize
    B4XSeekBar1.MinValue = 8
    B4XSeekBar1.MaxValue = 38
    B4XSeekBar1.Interval = 1
    B4XSeekBar1.Update
   
    For i = 0 To 20
        clv1.AddTextItem("text item "& i,"item" & i)
    Next
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub B4XSeekBar1_ValueChanged (Value As Int)
    SetItemTextSize( Value)
End Sub

Public Sub SetItemTextSize (TextSize As Int)
    For i = 0 To clv1.Size - 1
        Dim item As CLVItem = clv1.GetRawListItem(i)
        Dim lbl As B4XView = item.Panel.GetView(0).GetView(0)
        #if B4J
        lbl.As(Label).Style = $"-fx-font-size:$1.2{TextSize};"$
        #Else
        lbl.TextSize = iTextSize
        #End If
        lbl.TextColor = xui.Color_Blue
        clv1.GetRawListItem(i).Panel.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_DarkGray, 6dip)
    Next
End Sub

GetRawListItem has other values that can be used to wrap the text when the text size changes
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Using B4XSeekBar is a good choice. The only small issues I see are:
1. It is hard to maneuver the seekbar interval with your finger.
2. You cannot tell the value being scrolled when navigating the bar unless you add a label displaying the value.
3. Unless you set the textsize initially to a large textsize, some of the items with the long text may be truncated when you increase the size. See snapshot.
4. How does it behave when you have a long list of items without lazy loading, I am not sure.
1687640399165.png

That is why I went with B4XPlusMinus
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
A third method you can add to your repertoire is using a B4XPlusMinus instead of 2 buttons:
B4X:
Sub PlusMinus_ValueChanged (Value As Object)
    SetTextItemSize(Value)
End Sub

Public Sub SetTextItemSize(tsize As Float)
    For i = 0 To clv1.Size - 1
        Dim lbl As B4XView = clv1.getPanel(i).GetView(0)
        #if B4J
        lbl.As(Label).Style = $"-fx-font-size:$1.2{tsize};"$
        #Else
        lbl.TextSize = tsize
        #End If
        lbl.TextColor = xui.Color_Black
        clv1.getPanel(i).SetColorAndBorder(xui.Color_White, 5dip, xui.Color_DarkGray, 6dip)
    Next
End Sub

View attachment 143163
Has it been tested on B4i? How is the response?
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Why did you decide not to show your code with this BubbleSeekBar? It does not look like a B4XSeekBar to me.
thanks @klaus
 
Upvote 0
Top