Android Question Cards list with CustomListView - Control ToggleButton on card

james_sgp

Active Member
Licensed User
Longtime User
Hi, I`m using the 'XcustomListView with a Card' I have a toggle button on the card (its a Todo list); how can I check/uncheck the toggle button with code. I can get the card number using
"Dim index As Int = checklist_clv.GetItemFromView(Sender)" but can't see how that can help me...

Thanks, James
 

mangojack

Well-Known Member
Licensed User
Longtime User
Adding a toggle button to the CLV Card View Example ...

B4X:
Sub lblAction1_Click
    Dim index As Int = CLV1.GetItemFromView(Sender)
    Dim p As B4XView = CLV1.GetPanel(index)    'base panel
    Dim pp As B4XView = p.GetView(0)     'card panel   

    Log(pp.GetView(6).Checked)  'togglebutton 7th item on card ... refer Designer View Tree
    pp.GetView(6).Checked = True
   
    Log($"Action 1 clicked. Index: ${index}"$)
End Sub
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
B4X:
Private Sub CreateCheck1(my_brand As String, my_model As String, my_Title As String, my_Image As String, my_checks As String, status As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.setlayoutanimated(0,0%x,0%y,100%x,30%y)
    p.LoadLayout("checklist1")     
    brand_lbl.Text = my_brand & ", " & my_model
    title_lbl.Text = my_Title
    check_lbl.Text = my_checks
    Tog_but.Background=sld
    Tog_but.TextOff = ""
    Tog_but.TextOn = ""
  
    If File.Exists(File.DirAssets,my_Image) = True Then
        ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, my_Image, ImageView1.Width, ImageView1.Height, True)) 
    End If
    If my_Title = "PRE-BREATH" Then Tog_but.Visible = False 
  
    If status = "0" Then
        Tog_but.Checked = False
    End If
    If status = "1" Then
        Tog_but.Checked = True
    End If
    Return p
End Sub
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
That didn`t really help my situation, I have a toggle button that I am trying to set its status when populating the CLV, I`m storing the toggle button status in a KVS. Above is my code, its based on the Card xCLV demo.
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
We need more info ...

presuming that Tog_but is the toggle button on the Card layout "checklist1" the above code to change the checked status should work...

1. Is it only the Check State that is Not working ... is the other code to edit Tog_but properties working ? ie ( .Background, TextOff, TextOn & Visibility )
2.
are you sure that the passed status parameter contains the correct KVS setting.

try logging the passed "status" parameter on each Card load ...

ps: a slight code improvement also ...
B4X:
If my_Title = "PRE-BREATH" Then Tog_but.Visible = False
 
Log(status)
If status = "0" Then
    Tog_but.Checked = False
Else
    Tog_but.Checked = True
End If

If still having no luck , maybe upload a small sample project IDE > File > Export as Zip
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Also ... I am wondering if the above code should be further edited to only change the Checked status if Tog_but is Visible.

B4X:
If my_Title = "PRE-BREATH" Then
    Tog_but.Visible = False
Else
    Log(status)
    If status = "0" Then
        Tog_but.Checked = False
    Else
        Tog_but.Checked = True
    End If
End if

But without knowing exactly your projects / apps requirements I am unsure , but it is food for thought.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Thanks, i`ve now gone with a work around (which may even be better for my use); detecting the xCLV click and making an image visible/invisible.

Thanks for your help. James
 
Upvote 0
Top