Hello everyone, I would build a phone book consists of three editext: name, phone, address book, should work with sql lite, I'm not very good with the database, I have this code, the save button, memorize the data in the database, while the spinner call the selected item, the problem is that if a person memorize memorize it and then another, in the selection of the spinner always visualize a person and not the one corresponding to the storage, why?
I'll post some of my code and picture of the project.
I'll post some of my code and picture of the project.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("totems")
p.SetScreenOrientation(1)
If File.Exists(File.DirInternal, "totem.db") = False Then
File.Copy(File.DirAssets, "totem.db", File.DirInternal, "totem.db")
End If
dbSQL.Initialize(File.DirInternal, "totem.db", True)
PopulateSpinner
End Sub
B4X:
Sub PopulateSpinner
spagent.Clear
dbCursor = dbSQL.ExecQuery("SELECT * FROM Field2")
For I = 0 To dbCursor.RowCount - 1
DoEvents
dbCursor.Position = I
spagent.Add(dbCursor.GetString("Data2"))
Next
dbCursor.Close
End Sub
B4X:
Sub agent_Click
dbSQL.ExecNonQuery2("INSERT INTO Field2 VALUES (?)", Array As String(txtname.Text))
dbSQL.ExecNonQuery2("INSERT INTO Field3 VALUES (?)", Array As String(txtlastname.Text))
dbSQL.ExecNonQuery2("INSERT INTO Field4 VALUES (?)", Array As String(txtphone.Text))
spagent.Add(txtlocale.Text)
txtname.Text = ""
txtlastname.Text=""
txtphone.Text=""
dbCursor.Close
End Sub
B4X:
Sub spagent_ItemClick (Position As Int, Value As Object)
txtname.Text = ""
txtlastname.Text = ""
txtphone.Text= ""
dbCursor = dbSQL.ExecQuery("SELECT * FROM Field2")
For I = 0 To dbCursor.RowCount - 1
DoEvents
dbCursor.Position = I
txtname.Text = (dbCursor.GetString("Data2"))
Next
dbCursor.Close
dbCursor = dbSQL.ExecQuery("SELECT * FROM Field3")
For I = 0 To dbCursor.RowCount - 1
DoEvents
dbCursor.Position = I
txtlastname.Text = (dbCursor.GetString("Data3"))
Next
dbCursor.Close
dbCursor = dbSQL.ExecQuery("SELECT * FROM Field4")
For I = 0 To dbCursor.RowCount - 1
DoEvents
dbCursor.Position = I
txtphone.Text = (dbCursor.GetString("Data4"))
Next
dbCursor.Close
End Sub