Android Question CLVSwipe. Swipe right/left and Material Iconcs

red30

Well-Known Member
Licensed User
Longtime User
Is it possible to use right and left shift at the same time? If so, how can this be done?
I tried to set the "icon" instead of the text, but it is not displayed.
B4X:
CustomListView1.AddTextItem(cs, Swipe.CreateItemValue("", Array(Chr(0xF0EE), "text")))
Why? Is it possible to use “Material Iconcs” and a picture instead of text?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
CLVSwipe only supports swiping from the right to the left.

Is it possible to use “Material Iconcs” and a picture instead of text?
Yes. Two options:

1. Modify CreateActionButtons and set the font with XUI.CreateMaterialIcons.
2. Modify CreateActionButtons and set the type of action iterator to Object. This will allow you to pass CSBuilders instead of simple strings and set the font. You do need to test it as it can has other effects.
 
Upvote 0

AlexMaa

Member
Licensed User
Longtime User
1. Modify CreateActionButtons and set the font with XUI.CreateMaterialIcons.
2. Modify CreateActionButtons and set the type of action iterator to Object. This will allow you to pass CSBuilders instead of simple strings and set the font. You do need to test it as it can has other effects.

I can't do it. I need both the icon and the text. can I see the code?

Swipe.CreateItemValue("", Array( Chr(0xE872) & " delete")) - not work
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I can't do it. I need both the icon and the text. can I see the code?

In the CLVSwipe class module, replace the sub CreateActionButtons with this sub:
B4X:
Private Sub CreateActionButtons (actions As List) As Int
    ActionsPanel.RemoveAllViews
    Dim LastX As Int = 0
    For Each action As Object In actions
        Dim l As Label
        l.Initialize("lbl")
        Dim xlbl As B4XView = l
        Dim cs As CSBuilder  'Some of the lines below Mahares added them to create icons to action buttons
        cs.initialize.Append(action).PopAll
        xlbl.Text = cs
        xlbl.Color = ActionColors.GetDefault(action, xui.Color_White)
        xlbl.SetTextAlignment("CENTER", "CENTER")
        xlbl.Font = xui.CreateDefaultBoldFont(20)
        xlbl.TextColor = xui.Color_Black
        Dim width As Int = Max(40dip, cvs.MeasureText(action, xlbl.Font).Width + 20dip)
        ActionsPanel.AddView(xlbl, ActionsPanel.Width - width - LastX, 0, width, ActionsPanel.Height)
        LastX = LastX + width
    Next
    Return LastX
End Sub

And in Sub CreateItems of the main activity, you add this code:
B4X:
If i Mod 3 = 0 Then
            cs.Append($"Important item ${i} ..."$).PopAll
            Dim MyList As List
            MyList.Initialize
            Dim csa As CSBuilder
            MyList = Array(csa.Initialize.Color(xui.Color_Red).Typeface(Typeface.MONOSPACE).Size(20). _
            Append("Delete ").Typeface(Typeface.MATERIALICONS).Append(Chr(0xE872)).PopAll)
            CustomListView1.AddTextItem(cs, Swipe.CreateItemValue("",MyList))
If you do all the above, you will be in heaven.
 
Upvote 0

AlexMaa

Member
Licensed User
Longtime User
Thank you very much!
in Android - work

One problem - it doesn't work in iOS !

Dim xlbl As B4XView
xlbl.Text = <--- only string
xlbl.AttributedText = <--- there is no such method
 
Last edited:
Upvote 0

AlexMaa

Member
Licensed User
Longtime User
thanks. everything worked out. there is a small problem with calculating the width size. but not critical

B4X:
Dim width As Int = Max(60dip, cvs.MeasureText(action, xlbl.Font).Width + 20dip)
 
Upvote 0
Top