Android Question MaterialFavoriteButton for B4X pages

mscientist33

Active Member
Licensed User
I have got the MaterialFavoriteButton from here: MaterialFavoriteButton but it uses Activities. Does anyone have an example how to make this work with B4X pages? I would like to use this for each item in a xCustomListView.
 

Marvel

Active Member
Licensed User
I've never used the MaterialFavouriteButton but you can get the main activity with this:

B4X:
B4xPages.GetNativeParent(Me)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Are you looking for something like this in an xClv
 

Attachments

  • mscientist100321.png
    mscientist100321.png
    12.9 KB · Views: 134
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I sure am @Mahares!!
Here is a complete B4XPages project. You just paste this code. The MainPage layout has the xClv. The item layout has the one label: Label1. This will give you some ideas you can build on and tweak.it around to include part of it in your project
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private xClv As CustomListView
    Private Label1 As B4XView
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")   'has xClv
    Dim l As List  = Array(Chr(0xF004), Chr(0xF08A), Chr(0xF005), Chr(0xF006))  'flled heart, heart, filled star, star
    For i =0 To 10
        Dim cs As CSBuilder
        cs.Initialize.size(50).color(xui.Color_Red).Typeface(Typeface.FONTAWESOME).Append(l.Get(Rnd(0, l.Size))).pop.color(xui.Color_Black).Append("   " ).Append(i).PopAll
        xClv.Add(CreateItems(cs), i)
    Next
End Sub

Sub CreateItems(c As CSBuilder) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0, xClv.AsView.Width, 75dip)
    p.LoadLayout("item")   'has label1
    Label1.Text = c 
    Return p
End Sub

Private Sub xClv_ItemClick (Index As Int, Value As Object)
    Log(Value)
End Sub
 
Upvote 0

mscientist33

Active Member
Licensed User
Thanks!! @Mahares You've helped me on just about every question I have asked!

Is there a way to tell which icon(text) the label is currently? I'm trying to use it as a checkbox.

This is what I am currently trying:

B4X:
Dim ItemIndex As Int = Verses.GetItemFromView(Sender)
   
Dim ItemIndex As Int = Verses.GetItemFromView(Sender)
    
    Dim p As B4XView = Verses.GetPanel(ItemIndex)
    'ToastMessageShow(p.GetView(3).Tag,False)
    Dim cblabel As Label=p.GetView(3)
    ToastMessageShow("label font: " & cblabel.Text, False)
        cs.Initialize.size(14).color(xui.Color_Red).Typeface(Typeface.FONTAWESOME).Append(favicon.Get(0)).pop.color(xui.Color_Black).Append("   " ).PopAll'.Append(i).PopAll
        cblabel.Text=cs

I am currently only using the hearts. I need to check if it is the 0xF08A then change it to the 0xF004. This works on changing it when clicked but I don't know how to tell which it is already using.
 
Last edited:
Upvote 0

mscientist33

Active Member
Licensed User
Finally got it @Mahares. I just had to pay attention to what the list was actually doing. This is what I got and I can go from there I hope. haha

B4X:
Dim ItemIndex As Int = Verses.GetItemFromView(Sender)
    
    Dim p As B4XView = Verses.GetPanel(ItemIndex)
    'ToastMessageShow(p.GetView(3).Tag,False)
    Dim cblabel As Label=p.GetView(3)
    
    If cblabel.Text=Chr(0xF08A) Then
    cblabel.Text=Chr(0xF004)
        Else
            cblabel.Text=Chr(0xF08A)
        End If
 
Upvote 0
Top