Android Question Button click event from all value from custom listview

Hi, Sir
I have delayed. Please help me with my problem.
In my custom listview, it involved 1 label and four radio button. I have one button that not in custom listview but same activitie. (I want to make quiz project. The data from website and it comes with json data). The button(Answer button),
I want > when I click button, I want to pick up data from custom listview(id and radiobutton.text which have checked)

I hop you help me this.
I apologize for my english skill if mistake include.
Best regard:
 
'In customlisvew Ch(4) As Radiobutton
Ch(0).Initialize("Ch")
Ch(0).Tag=0
Ch(1).Initialize("Ch")
Ch(1).Tag=1
Ch(2).Initialize("Ch")
Ch(2).Tag=2
Ch(3).Initialize("Ch")
Ch(3).Tag=3

Sub Ch_CheckedChange(Checked As Boolean)
If Checked =True Then
' Dim rbt As RadioButton
rbt=Sender
If rbt.Tag=index Then
rbt.Tag=rbt.Text
Else
rbt.Tag=""
End If
End If
End Sub


Sub button_Click

'I want to checked radio text according to ID

End Sub
 
Upvote 0
aa.png
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I want to checked radio text according to ID
This is one way to do it. See code and the 2 attached screenshots Designer Tree hierarchy and xClv display based on your post screenshot for each xClv item.
B4X:
Private Sub Button1_Click
    For i= 0 To xClv.Size-1
        Dim pp As B4XView= xClv.GetPanel(i)
        Log(pp.GetView(0).Text)
        If pp.GetView(1).Checked Then
            Log(pp.GetView(1).Text)
        else if pp.GetView(2).Checked Then
            Log(pp.GetView(2).Text)
        else if pp.GetView(3).Checked Then
            Log(pp.GetView(3).Text)
        else if pp.GetView(4).Checked Then
            Log(pp.GetView(4).Text)
        End If
    Next
End Sub
The output is:
What is your name
Four
What is your hobby
Football
Where do you live
Mandalay
 

Attachments

  • ItemTree.PNG
    ItemTree.PNG
    18.6 KB · Views: 264
  • xClvWithSelectedItems.png
    xClvWithSelectedItems.png
    16.6 KB · Views: 211
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I appreciate the code posted by @Mahares as it demonstrates how to "scan" an xCustomListView.

However, I would do it differently, as I have already written: I would exploit the events (mainly Click, of course) of the individual Views contained in the xCLV to store the user's choices (for example to a Map).
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I'm now ok
Here is another way of doing it:
B4X:
Sub rd_CheckedChange(Checked As Boolean)   'all 4 radio buttons have the same CheckedChange event: rd
    Dim index As Int = xClv.GetItemFromView(Sender)
    Dim p As B4XView =xClv.GetPanel(index)   
    Dim r As RadioButton=Sender
    If r.Checked  Then
        mp.Put(p.GetView(0).Text, r.Text)
    End If    
End Sub

B4X:
Private Sub Button1_Click   'Display the data selected from the questionnaire
    For Each k As String In mp.Keys  'mp is the map declared in Class_Globals and initialized in B4XPage_Created
        Log($"${k}${TAB}${mp.Get(k)}"$)
    Next
End Sub
The output will be something like this:
What is your name One
What is your hobby Reading
Where do you live Mandalay
If you agree, there is no need to follow-up.
 
Upvote 0
Top