Android Question sqlite position element into a spinner

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hi everyone, I have a sqlite database in my app, I use it to store products from a pizzeria in a spinner, I have a problem, when I insert a product and then I save it and after storing in the spinner for example 5 elements and I would like to delete the third element because I was wrong in writing the name of the element and therefore after having eliminated it I would like to be able to always insert on the same place (in third place) the element just removed, instead it adds it to the end of the spinner, these are the codes I use for save the item and delete the item.
B4X:
Sub btnm1_Click
   
   dbSQL.ExecNonQuery2("INSERT INTO field1 VALUES (?)", Array As String(txtmenu.Text & " - " & "Euro" & " " & txtcaricoeuro.Text))
            spm1.Add (txtmenu.Text & " " & "Euro" & " " & txtcaricoeuro.Text)
            txtcaricoeuro.Text="" ' pulisco la casella di testo txtcaricoeuro.text
            dbCursor.Close
          

            Msgbox("item added","stored")
            txtmenu.Text=""
   
   
    phone1.HideKeyboard(Activity)
    txtcaricoeuro.Text=0
End Sub
this is the code to delete the item
B4X:
Sub btnm1_LongClick
dbSQL.ExecNonQuery2("DELETE FROM field1 WHERE data1 = ?", Array As String(spm1.SelectedItem))
        Msgbox ("item removed from spinner menù ","NOTE")
        reset
end sub

if the element was removed in the third position of the spinner, how can I always put it back in the same position?
 

LucaMs

Expert
Licensed User
Longtime User
When you have those kind of problems, check what methods do you have available, what methods exist for the Spinner object?

You will see that there is a method to remove a certain item (RemoveAt) but you don't have a method to INSERT an element.

So... you have to re-fill the spinner or use a different View (xCustomListView, for example).



Moreover, if you write in the italian forum, I shouldn't be struggling to translate! :D
 
Last edited:
Upvote 0
Top