Android Question CustomListView - RadioButton


Active Member
Licensed User
Hi community I'm having problems with the configuration of a customlistview.
I added a layout in which there is a radiobutton, I can not cause the previous one to be disabled when the next radiobutton is clicked. Some idea?


Well-Known Member
Licensed User
Do you mean that in every single item there is only 1 Radio button?
In that case I think that it's a normal behaviour because every panel/item will work on it's own.
If you need to show that 1 item is selected above the others maybe you should use 1 checkbox in every item and make a cicle to disable all the others when 1 got selected.
Last edited:
Upvote 0

Albert Kallal

Active Member
Licensed User
I can suggest. (but I still rather new to the CustomListView object model. There is likely a better way, but I assume that in your code that "adds" the button to each row you have something like this:
   Dim p As     B4XView = xui.CreatePanel("")
   p.SetLayoutAnimated(0,0,0,100%x, 35dip)


    Label1.Text       = Crsr.GetString("ID")
    Label2.Text       = Crsr.GetString("HotelName")
    Label3.Text       = Crsr.GetString("City")
    Label4.Text       = Crsr.GetString("FirstName")
    RadioButton1.Checked = False
    RadioButton1.Tag = Crsr.GetString("ID")

    ViewData.Tag      = Crsr.GetString("ID")
   Return p

Now (even from designer), add a event for the radio button.

And, that code, you get this
Sub RadioButton1_CheckedChange(Checked As Boolean)
    Dim r As RadioButton = Sender
    Dim rRadioFromRow As RadioButton
    ' Log(r.Tag)    this gives the current row id.
    Dim i As Int
    For i = 0 To CustomListView1.Size - 1
        rRadioFromRow = CustomListView1.GetPanel(i).GetView(5)
        If rRadioFromRow.Tag <> r.Tag Then
            rRadioFromRow.Checked = False
        End If

Now, in above I had to "guess" which index the radio button is in the GetPanel. My spider sense tells me:
There is likely a better way to loop over each row.
There is likely a better way to get/grab/pull out the rRadioFromRow from the GetView.
However, the basic idea for above should work. I would hope the list is not too long.

And if anyone reading this?
Perhaps a for/each collection is available here? (I'm new to this).
So I not sure if above is the preferred way to loop over the custom list view.

However, while some kluge is in above? In theory the above idea is a means to do this. In above, for the tag setting I had a PK id from a data table, but anything from each row that can identify the separate row will work. (you could even use a loop counter in the panel add part).
I just don't know if a better means/way exists to figure out what index the radio button is in that "list".
So the 5 is a guess on my part - but it does work for me. You just have to figure out the index of the RadioButton in that single panel that you load for each row of the CustomListView.

Albert D. Kallal
Edmonton, Alberta, Canada
Upvote 0