Problem with linked spiner
Hello.
First, sorry for my bad English, I'm French (nobody is perfect
)
Second, sorry if the response is in another thread, I don't find it.
Third, sorry, but I'm a newbie in programming.
OK, that's all for apologize
I try to make an activity with 3 spiner and a SQL database.
Each spiner is linked to the next one: when the value of the first change, I must change the data in the second spiner etc... and the second modify the third... I hope I'm clear.
SQL description:
One table with many column, but only 3 necessary for this part of my program
The 3 columns are named: 'type', 'nom' and 'portion' (can have duplicate data)
In this example:
3 differents 'types', 3 differents 'nom' and 3 differents 'portion'.
One type can have 3 'nom' and one 'nom' can have 3 'portion'
For test, I named each data with the "parent name" like:
For 'type': 'data1 . data2 . data3'
For 'name': 'data1-1 . data1-2 . data1-3' if 'type' 'data1' is selected, or 'data2-1 . data2-2 . data2-3' if 'type' 'data2' is selected etc etc...
So the combination "data1 . data1-2 . data1-2-2' exist but, for example 'data1 . data2-1 . data1-3-2' don't exist.
I hope is OK for you
In this case, there is the same quatity of data on each combination, but in "real life", my program can have data with only one sub data and other one with a lot.
I check my SQL file with the SQLviewer and all data are correctly define.
I make a view with 3 spinner and try to code:
Don't worry for comments, in my program I put a lot of one, but I prefer delete them to post here (and they are in French of course...)
When I launch my program, no error (that's a good thing
) and the first data show on the spiner are correct (data1 . data1-1 . data1-1-1).
When I change 'type' to 'data2' for example, the spiner become (data2 - data2.1 - data2.1.1): OK
The problem occur after a couple of changes (for example, other combination cause problem):
1 - I change 'name' from 'data2-1' to 'data2-2' -> the 'Portion' spiner change to 'data2-2-x' : good
2 - I change 'type' from 'data2' to 'data3' -> the 'name' change to 'data3-2' and the 'Portion' change to 'data3-1-1'.
For the 'name', the result is correct, but I will prefer 'data3-1' (return to the first data of the spiner).Could you indicate to me the way to have the first data selected ?
For the 'Portion', the result is completely false. The combination 'data3 . data3-2 . data3-1-1' don't exist ! I can't see where is my mystake.
Could you help me please ?
Thanks for attention.
Hello.
First, sorry for my bad English, I'm French (nobody is perfect
Second, sorry if the response is in another thread, I don't find it.
Third, sorry, but I'm a newbie in programming.
OK, that's all for apologize
I try to make an activity with 3 spiner and a SQL database.
Each spiner is linked to the next one: when the value of the first change, I must change the data in the second spiner etc... and the second modify the third... I hope I'm clear.
SQL description:
One table with many column, but only 3 necessary for this part of my program
The 3 columns are named: 'type', 'nom' and 'portion' (can have duplicate data)
In this example:
3 differents 'types', 3 differents 'nom' and 3 differents 'portion'.
One type can have 3 'nom' and one 'nom' can have 3 'portion'
For test, I named each data with the "parent name" like:
For 'type': 'data1 . data2 . data3'
For 'name': 'data1-1 . data1-2 . data1-3' if 'type' 'data1' is selected, or 'data2-1 . data2-2 . data2-3' if 'type' 'data2' is selected etc etc...
So the combination "data1 . data1-2 . data1-2-2' exist but, for example 'data1 . data2-1 . data1-3-2' don't exist.
I hope is OK for you
In this case, there is the same quatity of data on each combination, but in "real life", my program can have data with only one sub data and other one with a lot.
I check my SQL file with the SQLviewer and all data are correctly define.
I make a view with 3 spinner and try to code:
B4X:
Sub Process_Globals
Dim SQL1 As SQL
End Sub
Sub Globals
Dim bpAddNewFood As Button
Dim bpEfface As Button
Dim bpOK As Button
Dim edTxtQte As EditText
Dim lbPoints As Label
Dim spinNom As Spinner
Dim spinPortion As Spinner
Dim spinType As Spinner
End Sub
Sub Activity_Create(FirstTime As Boolean)
SQL1.Initialize(File.DirDefaultExternal, "Database.db", False)
Activity.LoadLayout("formAddFood")
initChamps
End Sub
Sub initChamp()
' used to initialize spiner values at the start
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Type FROM table", Null, 0, spinType)
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Nom FROM table WHERE Type='" & spinType.SelectedItem & "'", Null, 0, spinNom)
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Portion FROM table WHERE Nom='" & spinNom.SelectedItem & "'", Null, 0, spinPortion)
End Sub
Sub spinType_ItemClick (Position As Int, Value As Object)
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Nom FROM table WHERE Type='" & spinType.SelectedItem & "'", Null, 0, spinNom)
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Portion FROM table WHERE Nom='" & spinNom.SelectedItem & "'", Null, 0, spinPortion)
End Sub
Sub spinNom_ItemClick (Position As Int, Value As Object)
DBUtils.ExecuteSpinner(SQL1, "SELECT DISTINCT Portion FROM table WHERE Nom='" & spinNom.SelectedItem & "'", Null, 0, spinPortion)
End Sub
Don't worry for comments, in my program I put a lot of one, but I prefer delete them to post here (and they are in French of course...)
When I launch my program, no error (that's a good thing
When I change 'type' to 'data2' for example, the spiner become (data2 - data2.1 - data2.1.1): OK
The problem occur after a couple of changes (for example, other combination cause problem):
1 - I change 'name' from 'data2-1' to 'data2-2' -> the 'Portion' spiner change to 'data2-2-x' : good
2 - I change 'type' from 'data2' to 'data3' -> the 'name' change to 'data3-2' and the 'Portion' change to 'data3-1-1'.
For the 'name', the result is correct, but I will prefer 'data3-1' (return to the first data of the spiner).Could you indicate to me the way to have the first data selected ?
For the 'Portion', the result is completely false. The combination 'data3 . data3-2 . data3-1-1' don't exist ! I can't see where is my mystake.
Could you help me please ?
Thanks for attention.
Last edited: