Android Question how can i reload records from json

Makumbi

Well-Known Member
Licensed User
How can i reload this activity Layout without first closing it because i want to see the new message received thanks

B4X:
'Do not forget to load the layout file created with the visual designer. For example:
    If  IsConnectedToInternet=True Then
    replysms
    Activity.LoadLayout("simplechat")
    Activity.Title="Chat"
    
        activestudents
    Dim SQLQry As String = "DELETE FROM SMSlist"
    Starter.SQL1.ExecNonQuery(SQLQry)
        cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
    If cursor1.RowCount > 0 Then
            cursor1.Position =0
        Dim phone As String
        phone = cursor1.Getstring("Phone")
            Dim sx As String
        sx = cursor1.Getstring("Sex")
        'Next
    End If
    Dim CustID As String = phone' Customer ID
    Dim jt As HttpJob
    jt.Initialize("", Me)
        jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBGetTeachers.ashx?customerid=" & CustID)
 
    jt.GetRequest.Timeout = 10000 ' 10 seconds
    Wait For (jt) JobDone(jt As HttpJob)
    If jt.Success Then ' if job is success (http status code 200)
        Dim RetVal As String
        RetVal = jt.GetString
        If jt.GetString = "[]" Then
            'Msgbox("Please try Again ","SMIS")
            'Return
            
        Else
            
            Dim jpt As JSONParser
            jpt.Initialize(jt.GetString)
            Log(jpt) ' will pr
            Dim quotes As List = jpt.NextArray
            For Each quot As Map In quotes
                '    Log("Account: " & quot.Get("Account"))
                    Log("Name: " & quot.Get("Name"))
                    Log("Category: " & quot.Get("Category"))
                    Log("atk: " & quot.Get("atk"))
                    Log("Code: " & quot.Get("Code"))
                    Dim ltt As Long
                    DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
                    Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Datesent")))
                    ltt = DateTime.DateParse(datestring)
                    DateTime.DateFormat = "dd/MM/yyyy"
                    Log(DateTime.Date(ltt))
            
  
                    Starter.SQL1.ExecNonQuery2("INSERT INTO SMSlist VALUES(?,?,?,?,?,?,?,?,?,?)", Array As Object(quot.Get("Account"), quot.Get("Name"), CustID,sx,quot.Get("sms"),DateTime.Date(ltt),quot.Get("atk"),quot.Get("Code"),quot.Get("Type"),1  ))
                    'Log(quot.Get("Account"))
                    'Log(quot.Get("Name"))
                    'Log(quot.Get(phone))
                    'Log(quot.Get(sx))
                    Log(RetVal) ' will print in log value returned from the server
                    
    
            '    End If
            Next
        
        End If
    
    'End If
    'InitSpinners
        'Msgbox("Records Processed Successfully. You Can Now Check ","SMIS")
    Else
        
            MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")
        Activity.LoadLayout("simplechat")
        Activity.Title="Chat"
        Return
        
        End If
        End If
End Sub
 

MarkusR

Well-Known Member
Licensed User
B4X:
Activity.RemoveAllViews
 

Makumbi

Well-Known Member
Licensed User
i
you are not doing any updates on the UI. How are you expecting it happens automatically?

Add the new downloaded Items to the already visible Listview/CustomListview/whatever.
i think you did not get me right
the json link at
B4X:
 jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBGetTeachers.ashx?customerid=" & CustID)
is getting newly sent messages but i wanted like a loop with can check for new changes in json records at
B4X:
 jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBGetTeachers.ashx?customerid=" & CustID)
so that get the new message and send out a notification to the user thanks
 

MarkusR

Well-Known Member
Licensed User
do you mean there are new recordsets /rows in this http response after each request and you will only add the new one to the activity?
then i would just compare the count or a last date stamp.
 

Makumbi

Well-Known Member
Licensed User
do you mean there are new recordsets /rows in this http response after each request and you will only add the new one to the activity?
then i would just compare the count or a last date stamp.
how can i do the comparison because currently what iam doing is to close the app then open again to check for new message
 

MarkusR

Well-Known Member
Licensed User
the name of your Sub is missing in your example code, i see only End Sub
u need a trigger, a button, a event, a timer
then you call your FetchData Sub again.
after you got this data you can compare it.
 

Makumbi

Well-Known Member
Licensed User
do you mean there are new recordsets /rows in this http response after each request and you will only add the new one to the activity?
then i would just compare the count or a last date stamp.
how can i do the comparison because currently i have to first close the app then open again to get the newly sent messages. This is the practical part of we get replies after we have sent out the message so i wanted to just get the new message which is delivered by
B4X:
jt.Download("http://kccug.com/Generic_Handler_JSON/HandlerVBGetTeachers.ashx?customerid=" & CustID)
without necessary having to close the activity layout
 

MarkusR

Well-Known Member
Licensed User
see #7
i guess you put your code in Activity_Resume? if yes then it is the wrong place.
 

Makumbi

Well-Known Member
Licensed User
the name of your Sub is missing in your example code, i see only End Sub
u need a trigger, a button, a event, a timer
then you call your FetchData Sub again.
after you got this data you can compare it.
exactly there you have got me but the uphill task is how to create that trigger and timer
 

Makumbi

Well-Known Member
Licensed User
exactly there you have got me but the uphill task is how to create that trigger and timer
Here is the complete code please thanks in advance
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type Message (Body As String, From As String)

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.
    Private txtMessage As EditText
    Private Rsms As EditText
    Private Rsms2 As Label
    Private Rsms3 As Label
    Private Rsms4 As Label
    Private classr As Label
    Private stream As Label
    Private account As Label
    Private txtLogs As EditText
    Private serializator As B4XSerializator
    Private chat As EditText
    Dim cursor1 As Cursor
    Private ClassAll As RadioButton
    Private RadioButton1 As RadioButton
    Private Nurse As RadioButton
    Private Admin As RadioButton
    Private spnFirstName As Spinner
    Private spnFirstName2 As Spinner
    Private badger1 As Badger
    Private btnSend As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    
    Activity.LoadLayout("2")
    badger1.Initialize
    If IsConnectedToInternet=True Then
        InitSpinners
        InitSpinners2
        Dim intCount As Int
        intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
            
        If intCount > 0 Then
            Dim ms As Int = intCount
        Else
            Dim ms As Int = 0
        End If
        Log(ms)
        badger1.SetBadge(btnSend, ms)
    Else
        MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")

        Return
        End If
End Sub


Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
    Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)

Dim m As Message = receivedObject
        CallSub2(chat, "NewMessage", m)
    
    End Sub
Private Sub CreateMessage(Body As String) As Byte()
    Dim m As Message
    m.Initialize
    m.Body = Body
    m.From = "currentName"
    Return serializator.ConvertObjectToBytes(m)
End Sub
Public Sub NewMessage(msg As Message)
    txtLogs.Text = $"${msg.From}: ${msg.Body}"$ & CRLF & txtLogs.Text
End Sub
Sub Activity_Resume
    badger1.Initialize
    Dim intCount As Int
    intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
            
    If intCount > 0 Then
        Dim ms As Int = intCount
    Else
        Dim ms As Int = 0
    End If
    Log(ms)
    badger1.SetBadge(btnSend, ms)
    cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
    
    If cursor1.RowCount<>0 Then
        'user registered
'    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = 0
        'Dim act As String= cursor1.GetString("Account")
        'Dim phone As String= cursor1.GetString("Phone")
        'Dim sx As String= cursor1.GetString("Sex")
        Rsms.Text=cursor1.GetString("sms")
        Log(Rsms.Text)
        Rsms2.Text=cursor1.GetString("Datesent")
        Log(Rsms2.Text)
        Rsms4.Text=cursor1.GetString("Atk")
        'Next
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnSend_Click
    If txtMessage.Text <> ""  And  RadioButton1.Checked=True Then
        cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
        If cursor1.RowCount > 0 Then
            cursor1.Position =0
            'Dim phone As String
            'phone = cursor1.Getstring("Phone")
            Dim sx As String
            sx = cursor1.Getstring("Sex")
            'Next
        End If
        Dim jBr As HttpJob
        jBr.Initialize("", Me)
        jBr.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBSingleparent.ashx?customerId=${txtMessage.Text}&customerId2=${account.Text}&customerId3=${sx}"$)
        txtMessage.Text=""
        MsgboxAsync("SMS Sent Successfully ", "SMIS")
        Return
    End If
    If txtMessage.Text <> ""  And  ClassAll.Checked=True Then
    cursor1 = Starter.SQL1.ExecQuery("SELECT Class,stream FROM Activeclass GROUP BY Class,stream")
    If cursor1.RowCount > 0 Then
        For i = 0 To cursor1.RowCount - 1
            cursor1.Position = i
            Dim clas  As String =cursor1.GetString("Class")
            Dim stre  As String =cursor1.GetString("stream")
        Next
    End If
    Dim jB As HttpJob
    jB.Initialize("", Me)
        jB.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBClassmessage.ashx?customerId=${txtMessage.Text}&customerId2=${clas}&customerId3=${stre}"$)
        txtMessage.Text=""
    MsgboxAsync("SMS Sent Successfully ", "SMIS")
    Return
    Else
        'Msgbox("You should type the Message you want to send ", "SMIS")
    End If
    If txtMessage.Text <> ""  And  ClassAll.Checked=False And  RadioButton1.Checked=False Then
    If txtMessage.Text <> "" Then
        If    spnFirstName.SelectedItem ="no filter" Then
            Msgbox("You Must Select the Student Name. ", "SMIS")
            spnFirstName.RequestFocus
            Return
        End If
         CallSub2(Starter, "SendMessage", txtMessage.Text)
        txtLogs.Text = txtMessage.Text
        CreateMessage(txtMessage.Text)
        
        Else
    If    txtMessage.Text="" Then
            MsgboxAsync("You Must Enter Some Text To Countinue. ", "SMIS")
            txtMessage.RequestFocus
            Return
        End If
        
        
        'NewMessage
    End If
    If IsConnectedToInternet=True Then
    cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Sentmessages")
    If cursor1.RowCount > 0 Then
        For i = 0 To cursor1.RowCount - 1
            cursor1.Position = i
            Dim NewID As Int
            NewID = cursor1.GetInt("ID")
        Next

    End If
            
    NewID = NewID +1      ' add 1 to the ID number to make a new ID field
    
    Dim l As Long
    DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
    Dim datestring As String = DateTime.Date(JsonDateToTick(DateTime.Now))
    l = DateTime.DateParse(datestring)
    DateTime.DateFormat = "dd/MM/yyyy"
            Log(DateTime.Date(l))
            Dim now As Long
            now = DateTime.Now
            Log(DateTime.Now)
            DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "hh:mm a"
            
            Log(DateTime.Date(l)& " "& DateTime.Time(now))
    'Starter.SQL1.ExecNonQuery("INSERT INTO Sentmessages VALUES('" & DateTime.Date(l)  & "','" & txtMessage.Text   & "','" & NewID & "')")
            Starter.SQL1.ExecNonQuery2("INSERT INTO Sentmessages VALUES(?, ?, ?)", Array As Object(DateTime.Date(l)& " "& DateTime.Time(now), txtMessage.Text, NewID))
    
    'txtMessage.Text=""
        cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,coded,Type FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
    If cursor1.RowCount<>0 Then
    'user registered
    For i = 0 To cursor1.RowCount - 1
        cursor1.Position = i
Dim act As String= cursor1.GetString("Account")
Dim phone As String= cursor1.GetString("Phone")
Dim sx As String= cursor1.GetString("Type")
Rsms.Text=cursor1.GetString("sms")
Dim cod As String=cursor1.GetString("coded")

                Next
                Dim now As Long
                now = DateTime.Now
                Log(DateTime.Now)
                DateTime.DateFormat = "dd/MM/yyyy" : DateTime.TimeFormat = "hh:mm a"
    Dim j As HttpJob
    j.Initialize("", Me)
                j.Download($"http://kccug.com/Generic_Handler_JSON/RecieveSMSReply.ashx?customerId=${act}&s=${txtMessage.Text}&d=${DateTime.Date(l)& " "& DateTime.Time(now)}&id=${cod}&ph=${phone}&f=${sx}&tk=${Rsms4.Text}"$ )
    
            txtMessage.Text=""
    
            cursor1 =Starter.SQL1.ExecQuery2("DELETE  FROM  SMSlist where Atk = ?", Array As String(Rsms4.Text))
            badger1.Initialize
            Dim intCount As Int
            intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Id) as Id FROM SMSlist")
            
            If intCount > 0 Then
                Dim ms As Int = intCount
            Else
                Dim ms As Int = 0
                End If
                If ms>0 Then
                    Dim mst As Int
                    mst=ms
                    Dim mstb As Int=1
                    ms = mst - mstb
                    Log(ms)
                    badger1.SetBadge(btnSend, ms)
                Else
                    Dim ms As Int = 0
                    badger1.SetBadge(btnSend, ms)
                End If
            
        MsgboxAsync("SMS Sent Successfully ", "SMIS")
    End If
    Else
    MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")

        Return
        End If
        End If
End Sub

Sub JsonDateToTick(s As String) As Long
    Dim m As Matcher = Regex.Matcher("\d+", s)
    If m.Find Then
        Return m.Match
    End If
    Log("Invalid date: " & s)
    Return 0
End Sub

Sub IsConnectedToInternet As Boolean
    Dim r As Reflector
 
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
    r.Target = r.RunMethod("getActiveNetworkInfo")
 
    If r.Target <> Null Then
        Return r.RunMethod("isConnectedOrConnecting")
    End If
 
    Return False
End Sub
Sub InitSpinners
    Private i As Int
    Private Query1 As String
    Private Curs As Cursor
    'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
    'We execute a query for each column and fill the Spinner
    'We use SELECT DISTINCT to have each existing first name in the database only once
    Query1 = "SELECT DISTINCT Account,Names FROM SMSlist ORDER BY Names ASC"
    Curs = Starter.SQL1.ExecQuery(Query1)
    'we add 'no filter' as no selection
    spnFirstName.Add("no filter")
    'we fill the Spinner with the data from the database
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        'spnFirstName.Add(Curs.GetString("Account"))
        spnFirstName.Add(Curs.GetString("Names"))
        'Dim kk As String = Curs.GetString("Names")
        'Log(kk)
        
    Next
    'Curs.Close
    
End Sub

Sub InitSpinners2
    Private i As Int
    Private Query1 As String
    Private Curs As Cursor
    'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
    'We execute a query for each column and fill the Spinner
    'We use SELECT DISTINCT to have each existing first name in the database only once
    Query1 = "SELECT DISTINCT Account,Name FROM Activeclass ORDER BY Name ASC"
    Curs = Starter.SQL1.ExecQuery(Query1)
    'we add 'no filter' as no selection
    spnFirstName2.Add("no filter")
    'we fill the Spinner with the data from the database
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        'spnFirstName.Add(Curs.GetString("Account"))
        spnFirstName2.Add(Curs.GetString("Name"))
        'Dim kk As String = Curs.GetString("Names")
        'Log(kk)
        
    Next
    'Curs.Close
    
End Sub

Sub btnEdit_Click
    'ShowTable
End Sub

Sub spnFirstName_ItemClick (Position As Int, Value As Object)
    'cursor1.Close
    
    cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
    
    If cursor1.RowCount<>0 Then
        'user registered
    For i = 0 To cursor1.RowCount - 1
            cursor1.Position = 0
            If Rsms.Text = cursor1.GetString("sms") Then
                'Exit
                'Rsms.Text=""
            Else
                Rsms.Text=cursor1.GetString("sms")
                Log(Rsms.Text)
                Rsms2.Text=cursor1.GetString("Datesent")
                Log(Rsms2.Text)
                Rsms4.Text=cursor1.GetString("Atk")
            End If
        
    Next
    End If
    
End Sub

Sub spnFirstName2_ItemClick (Position As Int, Value As Object)
    If    spnFirstName2.SelectedItem ="no filter" Then
            RadioButton1.Checked=False
        Return
    End If
    cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Class,stream FROM Activeclass where Name = ?", Array As String(spnFirstName2.SelectedItem))
    If cursor1.RowCount<>0 Then
        'user registered
        For i = 0 To cursor1.RowCount - 1
            cursor1.Position = i
                account.Text=cursor1.GetString("Account")
            classr.Text=cursor1.GetString("Class")
            stream.Text=cursor1.GetString("stream")
            RadioButton1.Checked=True
        Next
    End If
End Sub

Sub Nurse_CheckedChange(Checked As Boolean)
    Private Answ As Int
        Answ = Msgbox2("Do you really want to Refer this Case to the Nurse?", "NURSE", "Yes", "", "No", Null)
        If Answ = DialogResponse.POSITIVE Then
        If Nurse.Checked=True Then
            Dim jt As HttpJob
            jt.Initialize("", Me)
            jt.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBNurse.ashx?customerId=${Rsms4.Text}"$ )
            Nurse.Checked=False
            cursor1 =Starter.SQL1.ExecQuery2("DELETE  FROM  SMSlist where Atk = ?", Array As String(Rsms4.Text))
            badger1.Initialize
            Dim intCount As Int
            intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
            
            If intCount > 0 Then
                Dim ms As Int = intCount
            Else
                Dim ms As Int = 0
            End If
            If ms>0 Then
                Dim mst As Int
                mst=ms
                Dim mstb As Int=1
                ms = mst - mstb
                Log(ms)
                badger1.SetBadge(btnSend, ms)
            Else
                
                cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
    
                If cursor1.RowCount<>0 Then
                    'user registered
'    For i = 0 To cursor1.RowCount - 1
                    cursor1.Position = 0
                    'Dim act As String= cursor1.GetString("Account")
                    'Dim phone As String= cursor1.GetString("Phone")
                    'Dim sx As String= cursor1.GetString("Sex")
                    Rsms.Text=cursor1.GetString("sms")
                    Log(Rsms.Text)
                    Rsms2.Text=cursor1.GetString("Datesent")
                    Log(Rsms2.Text)
                    Rsms4.Text=cursor1.GetString("Atk")
                    'Next
                    cursor1.Close
                End If
                Dim ms As Int = 0
                badger1.SetBadge(btnSend, ms)
            End If
            
            MsgboxAsync("SMS Forwarded Successfully ", "SMIS")
            End If
    End If
End Sub

Sub Admin_CheckedChange(Checked As Boolean)
    Private Answ As Int
    Answ = Msgbox2("Do you really want to Refer this Case to the Administrators?", "Admin", "Yes", "", "No", Null)
    If Answ = DialogResponse.POSITIVE Then
        If Admin.Checked=True Then
            Dim jt As HttpJob
            jt.Initialize("", Me)
            jt.Download($"http://kccug.com/Generic_Handler_JSON/HandlerVBAdmin.ashx?customerId=${Rsms4.Text}"$ )
            Admin.Checked=False
            cursor1 =Starter.SQL1.ExecQuery2("DELETE  FROM  SMSlist where Atk = ?", Array As String(Rsms4.Text))
            badger1.Initialize
            Dim intCount As Int
            intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Atk) as Id FROM SMSlist")
            
            If intCount > 0 Then
                Dim ms As Int = intCount
            Else
                Dim ms As Int = 0
            End If
            Log(ms)
            If ms>0 Then
                Dim mst As Int
                mst=ms
                Dim mstb As Int=1
                ms = mst - mstb
                Log(ms)
                badger1.SetBadge(btnSend, ms)
                Else
            
                cursor1 =Starter.SQL1.ExecQuery2("SELECT Account,Phone,Sex,sms,Datesent,Atk FROM SMSlist where Names = ?", Array As String(spnFirstName.SelectedItem))
    
                If cursor1.RowCount<>0 Then
                    'user registered
    For i = 0 To cursor1.RowCount - 1
                    cursor1.Position = 0
                    'Dim act As String= cursor1.GetString("Account")
                    'Dim phone As String= cursor1.GetString("Phone")
                    'Dim sx As String= cursor1.GetString("Sex")
                        If Rsms.Text = cursor1.GetString("sms") Then
                            Exit
                            
                    Else
                            Rsms.Text=cursor1.GetString("sms")
                            Log(Rsms.Text)
                            Rsms2.Text=cursor1.GetString("Datesent")
                            Log(Rsms2.Text)
                            Rsms4.Text=cursor1.GetString("Atk")
                        End If
                    Rsms.Text=cursor1.GetString("sms")
                    Log(Rsms.Text)
                    Rsms2.Text=cursor1.GetString("Datesent")
                    Log(Rsms2.Text)
                    Rsms4.Text=cursor1.GetString("Atk")
                    Next
                    cursor1.Close
                End If
                Dim ms As Int = 0
                badger1.SetBadge(btnSend, ms)
            End If
            
            MsgboxAsync("SMS Forwarded Successfully ", "SMIS")
        End If
    End If
End Sub
 

aeric

Well-Known Member
Licensed User
You mean you want refresh the items in spinner after you get the items from the web service?
 

MarkusR

Well-Known Member
Licensed User
you need to move the code in
Activity_Create & Resume to a own sub so that you can reuse it and call it by name if u need it somewhere.
use a menu or button first to call this sub after a click event.
 

Makumbi

Well-Known Member
Licensed User
i have sent this small sample proj please look at it and make for me adjustments as per the challenges
 

Attachments

aeric

Well-Known Member
Licensed User
In your Sendsms Activity module, add the following line

B4X:
Line 228:                cursor1 = Starter.SQL1.ExecQuery2("DELETE  FROM  SMSlist where Atk = ?", Array As String(Rsms4.Text))
Line 229:                InitSpinners      ' <- Add this line
Line 230:                badger1.Initialize
You need to clear the spinner first in InitSpinners sub
B4X:
Sub InitSpinners
    Private i As Int
    Private Query1 As String
    Private Curs As Cursor
    Query1 = "SELECT DISTINCT Account,Names FROM SMSlist ORDER BY Names ASC"
    Curs = Starter.SQL1.ExecQuery(Query1)
    spnFirstName.Clear      ' <- Add this line
    spnFirstName.Add("no filter")
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        spnFirstName.Add(Curs.GetString("Names"))   
    Next
    Curs.Close
End Sub
 

aeric

Well-Known Member
Licensed User
By the way, line 228 should be written as:
B4X:
Starter.SQL1.ExecNonQuery2("DELETE FROM SMSlist WHERE Atk = ?", Array As String(Rsms4.Text))
DELETE is Non query and does not need to return as cursor.
 

Makumbi

Well-Known Member
Licensed User
you need to move the code in
Activity_Create & Resume to a own sub so that you can reuse it and call it by name if u need it somewhere.
use a menu or button first to call this sub after a click event.
hi MarkusR have you succeeded with that small project i sent you
 
Top