Android Question Check if checkboxes have input

andredamen

Member
Licensed User
I want to know if one clicks on one of the checkboxes. How do I know that? Can anyone help me?

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = XUI.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("checkboxen")
    Label1.Text = Text
    Return p
End Sub
 

andredamen

Member
Licensed User
Thanks Agraham, but the checkboxes are in a CustomListView1. With "CustomListView1_ItemClick (Index As Int, Value As Object)" I can get the value and the index but not the checkbox. With checkboxchange I still dont't know witch checkbox (the index of the row). Is there a way to get the exact checkbox?
 
Upvote 0

Brian Dean

Active Member
Licensed User
An alternative, which is sometimes more convenient, is to give all of the checkboxes the same event name and use a single event handler. Give the checkboxes different Tag values so that the single event handler can determine which checkbox was activated.

[Sorry - overlapped with previous response.]
 
Upvote 0

andredamen

Member
Licensed User
Yes, the are called checkbox1 , 2 3 and 4

B4X:
    Private CustomListView1 As CustomListView
    Dim XUI As XUI
    
    Private CheckBox1 As B4XView
    Private CheckBox2 As B4XView
    Private CheckBox3 As B4XView
    Private CheckBox4 As B4XView
    Private Label1 As B4XView

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = XUI.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("checkboxen")
    Label1.Text = Text
    Return p
End Sub
 
Upvote 0

andredamen

Member
Licensed User
Private Sub checkbox1_CheckedChange(Checked As Boolean) works but then I don't know the index of the row. Checkbox1_CheckedChange(Checked As Boolean) react on all the checkboxes named checkbox1.
 
Upvote 0

andredamen

Member
Licensed User
This is what I am doing:

The layout "checkboxen" has label1 and 4 checkboxes. The whole thing is filled with database items. I can read the whole customlistview . Also the checkboxes, but when I click on a checkbox, I can't get that specific checkbox. So also not the tag. When I click on a checkbox I want to now which row and wich colom.


B4X:
Sub SQLTableRead

..........
........

    For i = 0 To Cursor1.RowCount - 1
        Dim Col(NumberOfColumns) As String
        Dim Dummy As String
        Cursor1.Position = i
        Col(0) = Cursor1.GetString(ColumnName(0))
        Col(4) = Cursor1.GetString(ColumnName(4))
        Dummy = " (" &  Cursor1.GetString(ColumnName(2)) & ")"

        CustomListView1.Add(CreateListItem(Col(0) & Dummy, CustomListView1.AsView.Width, 45dip),Col(4))

     .....................
     ..................

next

end sub

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = XUI.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("checkboxen")
    Label1.Text = Text
    Return p
End Sub
 
Upvote 0

agraham

Expert
Licensed User
Try this - I think I've got the syntax right but if not the general idea is there!
B4X:
 CustomListView1.Add(CreateListItem(Col(0) & Dummy, CustomListView1.AsView.Width, 45dip, i),Col(4))

Sub CreateListItem(Text As String, Width As Int, Height As Int, index as Int) As Panel
    Dim p As B4XView = XUI.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("checkboxen")
    Checkbox1.tag = index
    Checkbox2.tag = index
    Checkbox3.tag = index
    Checkbox4.tag = index
    Label1.Text = Text
    Return p
End Sub

Private Sub Checkbox1_CheckedChange(Checked As Boolean)
   Dim chk as Checkbox = Sender.As(Checkbox)
   Dim index as Int = chk.Tag.As(Int)
   ' whatever
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
When I click on a checkbox I want to now which row and wich colom.
If all you are interested in is the row number and the content of the column ( and I am quoting you), you do not need a Checkbox1_CheckedChange(Checked As Boolean) event. You can get that with:
B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Log(Index)   'the row number
    Log(Value)   'the data stored in col(4) since this is your returned value from clv

    Dim p As B4XView =CustomListView1.GetPanel(Index)
    Log(p.GetView(0).Text) 'content of col(0) which is stored in the Label1.text, assuming Label1 is 1st in tree
End Sub
 
Upvote 0
Top