Android Question change state Spinner with Radio button in Customlistview

MroBurk

Member
Licensed User
Hi there, I created a custolistview, in which there are 3 radiobuttons and a spinner. If I use the 3 radiobuttons ,the spinner changes words, but if I add the radiobuttons and spinner in a customlistview It doesn't work... Do you have any Ideas?


without customlistview:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    GreenArr(0)= "green0"
    GreenArr(1)= "green1"
    RedArr(0)="red0"
    RedArr(1)="red1"
    RedArr(2)="red2"
    YellowArr(0)="yellow0"
    YellowArr(1)="yellow1"
    YellowArr(2)="yellow2"
    YellowArr(3)="yellow3"
   
    end sub
   
Private Sub RadioButtonGreen_CheckedChange(Checked As Boolean)
    Spinner1.Clear
    Spinner1.Prompt="Green"
    Spinner1.AddAll(GreenArr)
end sub

Private Sub RadioButtonRed_CheckedChange(Checked As Boolean)
        Spinner1.Clear
        Spinner1.Prompt="red"
        Spinner1.AddAll(RedArr)
   
       
End Sub

Private Sub RadioButtonyellow_CheckedChange(Checked As Boolean)
    Spinner1.Clear
    Spinner1.Prompt="yellow"
    Spinner1.AddAll(YellowArr)
       
End Sub



with customlistview:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    GreenArr(0)= "green0"
    GreenArr(1)= "green1"
    RedArr(0)="red0"
    RedArr(1)="red1"
    RedArr(2)="red2"
    YellowArr(0)="yellow0"
    YellowArr(1)="yellow1"
    YellowArr(2)="yellow2"
    YellowArr(3)="yellow3"
   
    'se carico layout in activity spinner e radiobutton funzionano perfettamente. se le metto nella custom list view no...
    For i = 0 To 20
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(20000,0,0,100%x,60dip)
        p.LoadLayout("Layout")
        CustomListView1.Add(p,i)
    Next
End Sub
 

Mahares

Expert
Licensed User
Longtime User
If you want to get help , your best bet is to upload your project , especially when you have layout files like you do. People don't have time to reconstruct your layouts to test if the project is not readily available
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Ok, Thanks...
You need to have all 3 radio buttons have the same event name in the Designer: RadioButton. Your full code for the activity name: With should be like this:
B4X:
Sub Globals
    Private Spinner1 As Spinner
    Dim GreenArr(2), RedArr(3),YellowArr (4)As String
    Private CustomListView1 As CustomListView
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    GreenArr(0)= "green0"
    GreenArr(1)= "green1"
   
    RedArr(0)="red0"
    RedArr(1)="red1"
    RedArr(2)="red2"
   
    YellowArr(0)="yellow0"
    YellowArr(1)="yellow1"
    YellowArr(2)="yellow2"
    YellowArr(3)="yellow3"
       
    For i = 0 To 20
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(200,0,0,100%x,80dip)
        p.LoadLayout("Layout")
        CustomListView1.Add(p,i)
    Next
   
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub RadioButton_CheckedChange(Checked As Boolean)
    Dim index As Int=CustomListView1.GetItemFromView(Sender)
    Log(index)
    Dim p As B4XView = CustomListView1.GetPanel(index)
    If p.GetView(0).GetView(1).Checked Then
        Dim s As Spinner = p.GetView(0).GetView(0)
        s.Clear
        s.AddAll(GreenArr)
'        Log("green")
    else if p.GetView(0).GetView(2).Checked Then
        Dim s As Spinner = p.GetView(0).GetView(0)
        s.Clear
        s.AddAll(YellowArr)
'        Log("yellow")
    Else if p.GetView(0).GetView(3).Checked Then
        Dim s As Spinner = p.GetView(0).GetView(0)
        s.Clear
        s.AddAll(RedArr)
'        Log("Red")       
    End If   
End Sub

Private Sub Button1_Click
    StartActivity(Main)
    Activity.Finish
End Sub
You also need to change the event name for the other activity: Without accordingly. You need to change the event name in code as same event name for it to work. Did not fool with activity: Without.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Do you have any Ideas?
Here is a complete project that will take care of your application using the WIth and the WIthout activities. All you need to do is unzip it and run it.
 

Attachments

  • xClvRadiobuttonsSpinner123021.zip
    13.9 KB · Views: 110
Upvote 0

MroBurk

Member
Licensed User
I'm really grateful for your help. I tried to do this before your correct project... for each radio-button I wrote the code you suggested.. And It works!!! But yours Project is better... Thank you so much...🙇‍♂️


in the "Without" activity

B4X:
Private Sub RadioButtonyellow_CheckedChange(Checked As Boolean)
    Spinner1.Clear
    RadioButtonyellow.Checked=True
    Spinner1.Prompt="yellow"
    Spinner1.AddAll(YellowArr)
end sub



in the "With" Activity
B4X:
Private Sub RadioButtonyellow_CheckedChange(Checked As Boolean)
    
    Dim index As Int=CustomListView1.GetItemFromView(Sender)
    Log(index)
    Dim p As B4XView = CustomListView1.GetPanel(index)
    If p.GetView(0).GetView(2).Checked Then
        Dim s As Spinner = p.GetView(0).GetView(0)
        s.Clear
        s.AddAll(YellowArr)
        '        Log("green")
    
    End If
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
for each radio-button I wrote the code you suggested.. And It works!
You do not want to duplicate code by writing the same sub for each radio button. That is the reason for using the Sender keyword. On a small project, you get away with it, but not on a large one. You do not need to answer back or bow, just put a 'like'
 
Upvote 0
Top