Private Cursor1 As Cursor
Sub btnCaricaDaDB
Cursor1 = SQL1.ExecQuery("....")
If Cursor1.RowCount = 0 Then
Msgbox("Non ci sono record", "Esecuzione query")
Return
End If
CaricaListView(0)
End Sub
Sub btnAvanti
If Cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Max(Cursor1.RowCount -1, Cursor1.Position + 1)
btnAvanti.Enabled = (Position < Cursor1.RowCount -1)
CaricaListView(Position)
End Sub
Sub btnIndietro
If Cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Min(0, Cursor1.RowCount -1)
btnIndietro.Enabled = (Position > 0)
CaricaListView(Position)
End Sub
Sub CaricaListView(Position As Int)
lvDati.Clear
Cursor1.Position = Position
lvDati.Add(getString("nominativo"))
'...
End Sub
Sub btnCaricaDaDB
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
If cursor1.RowCount = 0 Then
Msgbox("Non ci sono record", "Esecuzione query")
Return
End If
CaricaListView(0)
End Sub
Sub btnavanti_Click
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Max(cursor1.RowCount -1, cursor1.Position + 1)
btnavanti.Enabled = (Position < cursor1.RowCount -1)
CaricaListView(Position)
End Sub
Sub btnindietro_Click
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Min(0, cursor1.RowCount -1)
btnindietro.Enabled = (Position > 0)
CaricaListView(Position)
End Sub
Sub CaricaListView(Position As Int)
lvdb.Clear
cursor1.Position = Position
' lvdb.Add(getString("nominativo"))
lvdb.AddSingleLine(cursor1.GetString("nominativo"))
lvdb.AddSingleLine(cursor1.GetString("direzione"))
lvdb.AddSingleLine(cursor1.GetString("via"))
lvdb.AddSingleLine(cursor1.GetString("servizio"))
lvdb.AddSingleLine(cursor1.GetString("interno"))
lvdb.AddSingleLine(cursor1.GetString("telefono"))
lvdb.AddSingleLine(cursor1.GetString("fax"))
End Sub
Deve essere:Position = Max(cursor1.RowCount -1, cursor1.Position + 1)
Position = Max(0, cursor1.RowCount -1)Position = Min(0, cursor1.RowCount -1)
#Region Project Attributes
#ApplicationLabel: Rubrica Telefonica
#VersionCode: 1
#VersionName:'SupportedOrientations possible values: unspecified, landscape or portrait. #SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL1 As SQL
Dim SQL2 As SQL
Private cursor1 As Cursor
Dim voce As VoiceRecognition
Dim parla As TTS
Dim gps1 As GPS
Dim latitudine As Double
Dim longitudine As Double
Dim cliente As HttpClient
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
'Dim lsq As String
Dim lvdb As ListView
Dim txtnominativo As EditText
Dim txtvia As EditText
Dim txtdirezione As EditText
Dim txtservizio As EditText
Dim txtinterno As EditText
Dim txttelefono As EditText
Dim txtfax As EditText
Dim txtntel As EditText
Dim btnleggi As Button
Dim btnnuovo As Button
Dim btncerca As Button
Dim btnavanti As Button
Dim btncancella As Button
Dim btnindietro As Button
Dim Label1 As Label
Dim txtcerca As EditText
' Dim id As String
Dim id As Int
'Dim txtprimo As EditText
Dim txtmodifica As Button
Private Label2 As Label
Private Label3 As Label
Private Label4 As Label
Dim EditText1 As EditText
Private btnvoce As Button
Dim frase As String
Dim tempo As Long
Dim orario As String
Dim datario As String
Dim x As Int
Dim pagina As PhoneIntents
Dim tel As PhoneCalls
Dim contatti As Contacts
Dim lista As List
Dim incontatti As List
lista=contatti.GetAll
Dim countIt As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("rubrica")
voce.Initialize("voce")
parla.Initialize("parla")
x=0
If FirstTime Then
gps1.Initialize("GPS")
cliente.Initialize("cliente")
End If
File.Delete(File.DirInternal,"contatti.db") ' just for testing loads the original database
If Not (File.Exists(File.DirInternal,"contatti.db")) Then
File.Copy(File.DirAssets, "contatti.db", File.DirInternal, "contatti.db")
End If
SQL1.Initialize(File.DirInternal, "contatti.db", True)
lvdb.SingleLineLayout.ItemHeight = 25dip
lvdb.SingleLineLayout.Label.Height = 25dip
lvdb.SingleLineLayout.Label.TextSize = 14
lvdb.SingleLineLayout.Label.TextColor = Colors.Black
btnleggi_Click
Dim GD As GradientDrawable
GD.Initialize("TR_BL", Array As Int(Colors.Gray, Colors.LightGray))
Activity.Background = GD
lvdb.ScrollingBackgroundColor = Colors.Transparent
lvdb.FastScrollEnabled = True
End Sub
Sub Activity_Resume
If gps1.GPSEnabled=False Then
ToastMessageShow("Abilita il GPS, perchè risulta disabilitato", True)
StartActivity(gps1.LocationSettingsIntent)
Else
gps1.Start(0,0)
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnleggi_Click
lvdb.Clear 'need to clear the list
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
Log(cursor1.RowCount)
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
lvdb.AddSingleLine(cursor1.GetString("id")& " : " & cursor1.GetString("nominativo"))
Next
cursor1.Close
End Sub
Sub btnnuovo_Click
Dim NewID As Int
Try
NewID = SQL1.ExecQuerySingleResult("SELECT max(id) FROM tabella ") + 1
Catch
NewID = 1
End Try
SQL1.ExecNonQuery("INSERT INTO tabella VALUES('" & NewID & "','" & txtnominativo.text.Replace("'","''") & "','" & txtdirezione.text.Replace("'","''") & "','" & txtservizio.text.Replace("'","''") & "','" & txtvia.text.Replace("'","''") & "','" & txttelefono.text.Replace("'","''") & "','" & txtfax.text.Replace("'","''") & "','"& txtntel.text.Replace("'","''") & "')")
End Sub
Sub btncerca_Click
lvdb.Clear'need to clear the list
If txtcerca.Text.Trim.Length > 0 Then
cursor1 = SQL1.ExecQuery("Select * FROM tabella where nominativo like '%" & txtcerca.Text & "%' OR via like '%" & txtcerca.Text & "%' OR direzione like '%" & txtcerca.Text & "%' OR servizio like '%" & txtcerca.Text & "%' OR interno like '%" & txtcerca.Text & "%' OR telefono like '%" & txtcerca.Text & "%' OR fax like '%" & txtcerca.Text & "%'")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
txtnominativo.text=cursor1.getString("nominativo")
txtdirezione.text=cursor1.getString("direzione")
txtvia.Text=cursor1.GetString("via")
txtservizio.Text=cursor1.GetString("servizio")
txtinterno.Text=cursor1.GetString("interno")
txtntel.text=cursor1.getstring("telefono")
txtfax.Text=cursor1.GetString("fax")
Next
End If
cursor1.Close
End Sub
Sub voce_result(Succes As Boolean,Texts As List)
frase=Texts.Get(0)
EditText1.Text=frase
If frase="ciao" Then
parla.Speak("ciao",True)
Else if x=1 Then
x=0
parla.Speak("sto cercando " & frase,True)
StartActivity(pagina.OpenBrowser("http://www.google.it/search?q=" & frase))
Else if x=2 Then
x=0
parla.Speak("sto chiamando il numero " & frase,True)
StartActivity(tel.Call(frase))
else if x=3 Then
x=0
For w=0 To lista.Size-1
Dim contatto As Contact
contatto=lista.Get(w)
If contatto.Name.ToLowerCase=frase.ToLowerCase Then
StartActivity(tel.Call(contatto.PhoneNumber))
End If
Next
Else If x=4 Then
x=0
Else if frase="che ore sono" Or frase="che ora è" Then
tempo=DateTime.Now
orario=DateTime.Time(tempo)
parla.Speak(orario,True)
Else if frase="che giorno è oggi" Or frase="che giorno è" Or frase="data" Then
tempo=DateTime.Now
datario=DateTime.Date(tempo)
parla.Speak(datario,True)
else if frase="cerca su internet" Or frase="cerca parola" Then
parla.Speak("cosa devo cercare?",True)
x=1
Else if frase="telefona" Or frase="telefono" Or frase="chiama" Or frase="voglio telefonare" Then
parla.Speak("quale numero devo chiamare?",True)
x=2
Else if frase="contatto" Or frase="contatti" Or frase="chiama" Or frase="chiama amico" Or frase="chiama contatto" Then
parla.Speak("quale nome devo chiamare?",True)
x=3
Else if frase="dove sono" Or frase="dove" Then
parla.Speak("un attimo che mi informo", True)
StartActivity(pagina.OpenBrowser("https://maps.google.it/maps?q=" & latitudine & "," & longitudine & "+(tu+sei+qui) &iwloc=A&hl=it"))
Else if frase="ultime notizie" Or frase="ultime notizie" Or frase="notizie" Then
Dim richiesta As HttpRequest
richiesta.InitializeGet("http://www.televideo.rai.it/televideo/pub/solotesto.jsp?pagina=101")
cliente.Execute(richiesta,1)
Else if frase="cerca via" Then
parla.Speak("dove devo portarti?",True)
x=4
navigami(frase)
Else
parla.Speak("non ho capito",True)
End If
End Sub
Sub GPS_LocationChanged(luogo As Location)
latitudine=luogo.Latitude
longitudine=luogo.Longitude
End Sub
Sub cliente_ResponseSuccess(risposta As HttpResponse,identificativo As Int)
Dim testo As String
testo=risposta.GetString("UTF8")
Dim x As Int
Dim y As Int
x=testo.IndexOf("<pre style")
y=testo.IndexOf("</pre>")
testo=testo.SubString2(x+51,y)
parla.Speak(testo,True)
End Sub
Sub navigami(luogo As String)
parla.Speak("adesso ti porto a " & luogo, True)
Dim mappa As Intent
Dim indirizzo As String
indirizzo="google.navigation:q=" & luogo
mappa.Initialize(mappa.ACTION_VIEW,indirizzo)
mappa.SetComponent("googlemaps")
StartActivity(mappa)
End Sub
Sub btnCaricaDaDB
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
If cursor1.RowCount = 0 Then
Msgbox("Non ci sono record", "Esecuzione query")
Return
End If
CaricaListView(0)
End Sub
Sub btnavanti_Click
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Max(cursor1.RowCount -1, cursor1.Position + 1)
btnavanti.Enabled = (Position < cursor1.RowCount -1)
CaricaListView(Position)
End Sub
Sub btncancella_Click
SQL1.ExecNonQuery("DELETE FROM tabella where nominativo = '" & txtnominativo.text & "' ")
End Sub
Sub btnindietro_Click
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Min(0, cursor1.RowCount -1)
btnindietro.Enabled = (Position > 0)
CaricaListView(Position)
End Sub
Sub CaricaListView(Position As Int)
lvdb.Clear
cursor1.Position = Position
lvdb.AddSingleLine(cursor1.GetString("nominativo"))
lvdb.AddSingleLine(cursor1.GetString("direzione"))
lvdb.AddSingleLine(cursor1.GetString("via"))
lvdb.AddSingleLine(cursor1.GetString("servizio"))
lvdb.AddSingleLine(cursor1.GetString("interno"))
lvdb.AddSingleLine(cursor1.GetString("telefono"))
lvdb.AddSingleLine(cursor1.GetString("fax"))
End Sub
Sub lvdb_ItemClick (Position As Int, Value As Object)
Dim idvalue As String
idvalue = Value
countIt = idvalue.IndexOf(":") 'find location of sperator
idvalue = idvalue.SubString2(0,countIt) 'find first part of label text
id = idvalue
' cursor1 = SQL1.ExecQuery("SELECT * FROM tabella where id = '" & id & "' ")
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella where id = " & id )
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
txtnominativo.text=cursor1.getString("nominativo")
txtdirezione.text=cursor1.getString("direzione")
txtvia.Text=cursor1.GetString("via")
txtservizio.Text=cursor1.GetString("servizio")
txtinterno.Text=cursor1.GetString("interno")
txtntel.text=cursor1.getstring("telefono")
txtfax.Text=cursor1.GetString("fax")
Next
End Sub
Sub txtmodifica_Click
SQL1.ExecNonQuery("UPDATE tabella set nominativo ='" & txtnominativo.text.Replace("'","''") & "',direzione ='" & txtdirezione.text.Replace("'","''") & "',servizio ='" & txtservizio.text.Replace("'","''") & "',via ='" & txtvia.text.Replace("'","''") & "',interno ='"& txtinterno.text &"',fax ='"& txtfax.text &"', telefono ='"& txtntel.text &"' WHERE id = '" & id &"'")
End Sub
Sub btnvoce_Click
voce.Listen
End Sub
Mi da errore. Se clicco btnavanti mi visualizza nella lista in alto il nominativo che avevo già selezionato e se vado indietro mi dice che il cursor1 e chiuso e mi blocca tutta l'App.Prova a chiudere il cursore ( cursor1.Close ) nelle diverse sub dove non hai chiuso lo stesso
Type tImpiegato(Nominativo As String, Via As String, _
Direzione As String, Servizio As String, _
Interno As String, Telefono As String, Fax As String)
Private mImpiegato As tImpiegato
Activity_Create
mImpiegato.Initialize
Sub txtnominativo_TextChanged (Old As String, New As String)
mImpiegato.Nominativo = New
End Sub
Sub btnCaricaDaDB
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
If cursor1.RowCount = 0 Then
Msgbox("Non ci sono record", "Esecuzione query")
Return
End If
CaricaListView(0)
cursor1.Close
End Sub
Sub btnavanti_Click
lvdb.Clear'need to clear the list
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Min(cursor1.RowCount - 1, cursor1.Position + 1)
btnavanti.Enabled = (Position < cursor1.RowCount - 1)
CaricaListView(Position)
cursor1.Close
End Sub
Sub btnindietro_Click
lvdb.Clear'need to clear the list
cursor1 = SQL1.ExecQuery("SELECT * FROM tabella")
If cursor1.RowCount = 0 Then Return
Dim Position As Int
Position = Max(0, cursor1.RowCount - 1)
btnindietro.Enabled = (Position > 0)
CaricaListView(Position)
cursor1.Close
End Sub
Sub CaricaListView(Position As Int)
lvdb.Clear
cursor1.Position = Position
lvdb.AddSingleLine(cursor1.GetString("id")& " : " & cursor1.GetString("nominativo"))
End Sub
Non abbandonare; ci vuole pazienza e tempo. Come qualcuno dice: "Nessuno nasce imparato"Niente da fare Luca, ti ringrazio, c'ho provato ho fatto come mi hai spiegato e non mi riesce di capire il funzionamento. Abbandono mestamente il progetto e lo studio di B4A. Grazie comunque per il tempo che mi hai dedicato.
Non abbandonare; ci vuole pazienza e tempo. Come qualcuno dice: "Nessuno nasce imparato"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?