Android Question How to get selected row and delete it

Makumbi

Well-Known Member
Licensed User
Screenshot_1548942325.png
Please help me out iam trying to get the selected row from the list and then delete using its ID please help me out here is my sample code which i was trying out
B4X:
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(0)
    Starter.CurrentIndex = Row
    'Dim kk As String = Row
    'Log(kk)
    UpdateSelectedItem
   
    Return True 'Don't try to navigate to this URL
End Sub

Sub UpdateSelectedItem
    Private Answ As Int
   
    Answ = Msgbox2("Do you really want to delete the selected entry ?", "D E L E T E", "Yes", "", "No", Null)
   
    If Answ = DialogResponse.POSITIVE Then
  
   
        Starter.SQL1.ExecNonQuery("DELETE FROM Recievedsms WHERE ID = " & "1")
        ShowTable2
      
        lblSelectedItem.Text = ""
    End If
   
End Sub
 

mangojack

Expert
Licensed User
Longtime User
@Makumbi ... To Help others to help you , Could you possibly upload a smaller / trimmed project highlighting your problem...

Or at least hint , which of the 6 modules containing the above Subs , is the one you are having trouble with.



PS: In your code above .. why are you not using Starter.Currentindex in your Delete query ?

B4X:
  '..................
    Starter.SQL1.ExecNonQuery("DELETE FROM Recievedsms WHERE ID =" & Starter.Currentindex)
    ShowTable2
 
    lblSelectedItem.Text = ""
  End if
 
End Sub
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should use:
Starter.SQL1.ExecNonQuery("DELETE FROM Recievedsms WHERE ID =" & Starter.IDList.Get(Starter.Currentindex))

You read the IDs in ReadDataBaseIDs, you need to use those.
The table row index is not necessarily the data base row ID.

Maybe you need to adapt the ReadDataBaseIDs to the Query in ShowTable.

I agree with mangojacks comment.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
You should use:
Starter.SQL1.ExecNonQuery("DELETE FROM Recievedsms WHERE ID =" & Starter.IDList.Get(Starter.Currentindex))

You read the IDs in ReadDataBaseIDs, you need to use those.
The table row index is not necessarily the data base row ID.

Maybe you need to adapt the ReadDataBaseIDs to the Query in ShowTable.

I agree with mangojacks comment.
this is the error i get when i select the row to be deleted
An error has occurred in sub simple chat updateselecteditem (java line 1749) index out of bounds exception invalid index size is 0
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Well, with just this information, I cannot help!
sub simple chat updateselecteditem what is this?
In which B4A code line do you get the error?

I cannot test the program you posted in post #4.
I get an error:
Error occurred on line: 289 (NB6)
java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=default_HIGH pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 number=0 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)

etc.

You must give more information!
It is frustrating trying to help with lack of information and not working programs.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Well, with just this information, I cannot help!
sub simple chat updateselecteditem what is this?
In which B4A code line do you get the error?

I cannot test the program you posted in post #4.
I get an error:
Error occurred on line: 289 (NB6)
java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(channel=default_HIGH pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x0 color=0x00000000 number=0 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0)

etc.

You must give more information!
It is frustrating trying to help with lack of information and not working programs.
Iam very sorry please let us use this other one attached
 

Attachments

  • Newshipedata.zip
    84.5 KB · Views: 200
Upvote 0

advansis

Active Member
Licensed User
Longtime User
Usually I put the ID of the record in the first column, then hide the column... So have not to manage an additional list/map...
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Usually I put the ID of the record in the first column, then hide the column... So have not to manage an additional list/map...
Please clarify using the code above i did not get you clearly on how to do it . thanks for the support
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Usually I put the ID of the record in the first column, then hide the column... So have not to manage an additional list/map...
Please clarify using the code above i did not get you clearly on how to do it . thanks for the support
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Did you even read my reply in you other thread .. https://www.b4x.com/android/forum/t...n-invalid-index-size-is-0.102200/#post-641414

I have made the following changes to your uploaded project to get it working.

Replysms Module ..... DataBase has 4 Columns
B4X:
Starter.SQL1.ExecNonQuery2("INSERT INTO Recievedsms VALUES(?, ?, ?, ?)", Array As Object(DateTime.Date(ltt), quot.Get("sms"), quot.Get("Account"), quot.Get("Code")))


B4X:
Sub ReadDataBaseIDs2
'............................................
'We read only the ID column and put them in a List
    If Starter.flagFilterActive = False Then
        cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Recievedsms")'@@ Initially  ("SELECT ID FROM Sentmessages")
    Else
        cursor1 = Starter.SQL1.ExecQuery("SELECT ID FROM Recievedsms" & Starter.FilterQuery)    '@@ Inittially ("SELECT ID FROM Sentmessages" & Starter.FilterQuery)
    End If
'...........................................


B4X:
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)        '@@@  Originally ...   values(0)
   '...........................................................



Now .. while the sample works , it still needs a lot of thought and rework.
@advansis idea with the hidden db ID's is a good .. but I cannot help you as I have only used the Webview for displaying data occasionally way back when.

Must you use WebView ? As suggested in my previous replay , with CustomListView , you could retrieve DB ID's on initial Data Query and set that ID as a return value on each row click.... Instead of have a separate routine to build a reference List.

Anyway .. That's now 4 cents.
 

Attachments

  • SMSTest Sample.zip
    16 KB · Views: 214
Last edited:
Upvote 0
Top