kingofducks
Member
I have two RadioButtons and a Spinner, all generated in the same layout. I want to change variables according to the selected item from the list and to the checked RadioButton. If the user selects one item from the spinner, the value of a variable will change no matter which radiobutton is checked, if one radiobutton is checked, the value of another variable will be changed in one way, if the other radiobutton is checked, the value that variable will be changed in an other way, etc...
I have created a sub for each item in the spinner, in each of these sub I have been creating a if condition for the radiobuttons. The code is repeated multiple times, I've been trying to find another solution and I ended up wasting my time without finding a proper way to do it, so I continued this way hoping it would work.
My problem is : when i log the variables after the user checks the radio button and selects an item, the variables' values are incorrect, way out of their proportion and I don't know why.
Here is an example :
I am sorry for the long thread and i thank you in advance for your reply and for the accorded patience
I have created a sub for each item in the spinner, in each of these sub I have been creating a if condition for the radiobuttons. The code is repeated multiple times, I've been trying to find another solution and I ended up wasting my time without finding a proper way to do it, so I continued this way hoping it would work.
My problem is : when i log the variables after the user checks the radio button and selects an item, the variables' values are incorrect, way out of their proportion and I don't know why.
Here is an example :
B4X:
Sub Globals
Dim a As Int
Dim b As Int
Dim c As Int
Dim d As Int
Dim spinner1 As Spinner
Dim list1 As List : list1.initialize
Dim radiobutton1 As RadioButton
Dim radiobutton2 As RadioButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("mylayout")
list1.AddAll(Array As String("item1","item2", "item3", "item4", "item5"))
spinner1.AddAll(list1)
End Sub
Sub radiobutton1_CheckedChange(Checked As Boolean)
End Sub
Sub radiobutton2_CheckedChange(Checked As Boolean)
End Sub
Sub spinner1_ItemClick(Position As Int, Value As Object)
item1_selected(0,"item1")
item2_selected(1,"item2")
item3_selected(2,"item3")
item4_selected(3,"item4")
item5_selected(4,"item5")
End Sub
Sub item1_selected(Position As Int, Value As Object)
a = a + 6 'This value stays the same no matter which radiobutton is checked
If radiobutton1.Checked = True Then 'These are the variables I want to change if radiobutton1 is checked
b = b - 17
c = c + 12
End If
If radiobutton2.Checked = True Then 'And these if radiobutton2 is checked
b = b + 23
d = d - 8
End If
End Sub 'The code structure is the same for the other items only the values and the variables change
I am sorry for the long thread and i thank you in advance for your reply and for the accorded patience