Android Question Help with spinner

apty

Active Member
Licensed User
Longtime User
I have a situation which is a bit hard to explain but the following is the concept:
I have an app that loads data from sqlite. The user can then perform updates on the database. I have a spinner control used to load values .The spinner will load the value saved in, say, customer table. I want when the user clicks on the spinner, he should be able to get all values (saved in category table) and select a value then update the database. The following is my code
B4X:
Cursor1 = sql1.ExecQuery("SELECT *  FROM customer where code ='" & lblRowid.Text &"'")
  
      For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
    txtDate.Text=Cursor1.GetString("date")
    txtName.Text=Cursor1.GetString("name")
    SpinCategory.Add(Cursor1.GetString("category"))                      
                Next
I have tried using SpinCategory_ItemClick to load all category values (which loads the values) but when i click on the spinner, it just selects the first value as SelectedItem. If i select another value, the spinner defaults to first value. Please help
 

Linostar

Member
Licensed User
Longtime User
I wouldn't advise to load (and reload) all value with the ItemClick event, unless it is really necessary. In many cases, it's sufficiant to call the loading code in Activity_Resume for instance. However, if your design requires this, you can add this inside your ItemClick event (after your aforementioned code):

B4X:
Sub SpinCategory_ItemClick(Position As Int, Value As Object)
      '....

      SpinCategory.SelectedIndex = Position
End Sub
 
Upvote 0

Pilar-JLSineriz

Active Member
Licensed User
Longtime User
Dear friends, I have the following code but my spinner is not filled, which is the problem?? Kind regards.

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("screen2_pasivominero")
spnProvincias.Initialize("spnProvincias")

provSQL.Initialize(File.DirInternal, "PasivosMineros.sqlite", True)
provC=provSQL.ExecQuery("SELECT * FROM Provincias")

For i = 0 To provC.RowCount-1

provC.Position=i
spnProvincias.Add(provC.GetString("Nombre"))

Next
provC.Close
End Sub
 
Upvote 0

Pilar-JLSineriz

Active Member
Licensed User
Longtime User
Hello Klaus... yes yes.. .it was the problem, I solved it when I've just send the mail!!!!! Regards.. now I have problems with the new version and the debugging.. My brother continues bad :-(
 
Upvote 0
Top