Android Question Deleting selected row

Makumbi

Well-Known Member
Licensed User
Please i wanted to delete the selected row but i cant figure out how to get the values from the selected row
 

Attachments

  • Screenshot_1545578452.png
    Screenshot_1545578452.png
    77.6 KB · Views: 194

Makumbi

Well-Known Member
Licensed User
Unfortunately, you don't give enough information!
I suppose that the table is shown in a WebView.
Then, how do get the data?
How do you fill the table?
Do you use DBUtils?
etc.?

that is my code please
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.

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 wbvTable As WebView
    'Dim MaskedEditText1 As MaskedEditText
    'Dim MaskedEditText2 As MaskedEditText
    'Dim pnlLayout1, pnlLayout2 As Panel
    'Private lblSelectedItem As Label
    'Dim MaskedEditText1 As MaskedEditText
    'Dim MaskedEditText2 As MaskedEditText
    'Dim From As EditText
    'Dim Account As EditText
    Private HtmlCSS As String
    HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
        & " th { font-weight: bold;    background-color: #acf;    border-bottom: 1px solid #cef; }" _
        & "td,th {    padding: 4px 5px; }" _
        & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
        & "a { text-decoration:none; color: #000;}"
    'Dim froms As MaskedEditText
    'Dim sendtt As Button
End Sub

Sub ShowTable
    'Dim SQLQry As String = "DELETE FROM Balances"
    'Starter.SQL1.ExecNonQuery(SQLQry)
    Private Query As String
    Query = "SELECT DISTINCT Names,DESCRIPT,DEBITAMNT,CREDITAMNT,TREF, CASE WHEN TRDATE ='01/01/1970' THEN NULL ELSE TRDATE END AS TRDATE,BAL As Balance FROM Statement"
    'Query = "SELECT DISTINCT Names,DESCRIPT,DEBITAMNT,CREDITAMNT,TREF, TRDATE,BAL As Balance FROM Statement"
    
    'depending if the filter is active or not we add the filter query at the end of the query
    'the filter query is defined in the Filter Activity
    If Starter.flagFilterActive = False Then
        'btnFilter.Initialize("Filter")
        'btnFilter.Text = "Filter"    'change the text in the Filter button
    Else
        Query = Query & Starter.FilterQuery
        'btnFilter.Text = "UnFilter"    'change the text in the Filter button
    End If
    'displays the database in a table
    wbvTable.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
    ReadDataBaseIDs
End Sub
Sub ReadDataBaseIDs
    Private Row As Int
    Private cursor1 As Cursor
    
    Starter.IDList.Initialize        'initialize the ID list

    'We read only the ID column and put them in a List
    If Starter.flagFilterActive = False Then
        cursor1 = Starter.SQL1.ExecQuery("SELECT Account FROM Statement")
    Else
        cursor1 = Starter.SQL1.ExecQuery("SELECT Account FROM Statement" & Starter.FilterQuery)
    End If
    
    If cursor1.RowCount > 0 Then                        'check if entries exist
        Starter.RowNumber = cursor1.RowCount                    'set the row count variable
        Starter.IDList.Initialize                                            'initialize the ID list
        For Row = 0 To  Starter.RowNumber - 1
            cursor1.Position = Row                            'set the Cursor to each row
            Starter.IDList.Add(cursor1.GetInt("Account"))        'add the ID's to the ID list
        Next
        Starter.CurrentIndex = 0                                            'set the current index to 0
    Else
        Starter.CurrentIndex = -1                                            'set the current index to -1, no selected item
        ToastMessageShow("No items found", False)
    End If
    cursor1.Close                                                        'close the cursor, we don't need it anymore
End Sub

Sub wbvTable_OverrideUrl (Url As String) As Boolean
    'parse the row and column numbers from the URL
    Private values() As String
    values = Regex.Split("[.]", Url.SubString(7))
    Private row As Int
    row = values(1)
    Starter.CurrentIndex = row
    UpdateSelectedItem
    
    Return True 'Don't try to navigate to this URL
End Sub

Sub UpdateSelectedItem
    'Private Query As String
    'Private Curs As Cursor
    
    'Query = "SELECT DISTINCT Account,Names, Class,Stream,Amount FROM Balances WHERE ID = " & Starter.IDList.Get(Starter.CurrentIndex)
    'Curs = Starter.SQL1.ExecQuery(Query)
    'Curs.Position = 0
    'lblSelectedItem.Text = Curs.GetString("Names") & " " & Curs.GetString("Class")& " " & Curs.GetString("Amount")
    'Account.Text = Curs.GetString("Account")
    'Curs.Close
End Sub
Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean) As String
    Private cur As Cursor
    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    Log("ExecuteHtml: " & Query)
    If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
    Private sb As StringBuilder
    sb.Initialize
    sb.Append("<html><body>").Append(CRLF)
    sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
    sb.Append("<table><tr>").Append(CRLF)
    For i = 0 To cur.ColumnCount - 1
        sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
    Next
    
    sb.Append("</tr>").Append(CRLF)
    For row = 0 To Limit - 1
        cur.Position = row
        If row Mod 2 = 0 Then
            sb.Append("<tr>")
        Else
            sb.Append("<tr class='odd'>")
        End If
        For i = 0 To cur.ColumnCount - 1
            sb.Append("<td>")
            If Clickable Then
                sb.Append("<a href='http://").Append(i).Append(".")
                sb.Append(row)
'                sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
                sb.Append(".stub'>").Append(cur.GetString2(i)).Append("</a>")
        
            Else
                sb.Append(cur.GetString2(i))
            End If
            sb.Append("</td>")
        Next
        sb.Append("</tr>").Append(CRLF)
        
    Next
    cur.Close
    sb.Append("</table></body></html>")
    Return sb.ToString
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.Finish
    Activity.LoadLayout("Statementdisplay")
    Activity.Title="Provisional Account Statement"
    
    ShowTable
    'Starter.SQL1.ExecQuery("UPDATE Statement SET TRDATE =NULL WHERE TRDATE=01/01/1970")
End Sub

Sub Activity_Resume
    'StartActivity(Accountstatement)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    StartActivity(Accountstatement)
'StartActivity(Accountstatement)
    'Activity.RemoveAllViews
    'Activity.LoadLayout("AccountStatement")
    'Activity.Title="Provisional Account Statement"
    'ShowTable2
End Sub



Sub Button1_Click
    Activity.Finish
End Sub
 
Upvote 0
Top