Android Question DELETE A LISTVIEW RECORD !!

MarcioCC

Member
Licensed User
Longtime User
Good night, does anyone have an example of how to delete a record from a listview ?? I'm adding records in a listview I want to click a row in the listview and delete the record
The command I am using to add the records in the database is this:
S.ExecNonQuery2 ("INSERT INTO PRODUCTS (rowid, CODBARRAS, QUANTITY) VALUES (NULL,?,?)", Array As String (Edtdescr.Text, EdtQtde.Text))

I give a SELECT
C = s.ExecQuery ("SELECT CODBARRAS, QUANTITY FROM PRODUCTS ORDER BY CODBARRAS, QUANTITY")

And add in the listview
Lvadiciona.AddTwoLines (C.GetString ("CODBARRAS"), C.GetString
("AMOUNT"))

I want to click on the row in the listview to select the record and delete.
Thank you !!
 

mangojack

Well-Known Member
Licensed User
Longtime User
B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)   
    ListView1.RemoveAt(Position)   
End Sub
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Remove from the ListView or remove from the Database? I guess both.

Something like this :

B4X:
Sub ListView_ItemLongClick (Position As Int, Value As Object)

    Dim result As Int

    result = Msgbox2("Are you sure?", "Remove selected Favourite", "Yes", "", "No", Null)

    If result = DialogResponse.Positive Then

        SQL1.ExecNonQuery("DELETE FROM table where id = '" & Value & "'")

    're-populate the listview of FAVOURITEs 

    RepopulateListView

    EndIf

EndSub

I use a Long Press to remove certain items from a list and then call a sub I've defined to Repopulate the list displayed.

HTH
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Remove from the ListView or remove from the Database? I guess both.

Something like this :

B4X:
Sub ListView_ItemLongClick (Position As Int, Value As Object)

    Dim result As Int

    result = Msgbox2("Are you sure?", "Remove selected Favourite", "Yes", "", "No", Null)

    If result = DialogResponse.Positive Then

        SQL1.ExecNonQuery("DELETE FROM table where id = '" & Value & "'")

    're-populate the listview of FAVOURITEs

    RepopulateListView

    EndIf

EndSub

I use a Long Press to remove certain items from a list and then call a sub I've defined to Repopulate the list displayed.

HTH
[fussiness?]: it is better to show (Msgbox2) some data of the record to be deleted (at least the "Value") rather than the generic text like "Remove selected".
 
  • Like
Reactions: eps
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Well, I saw SWs where you get:

"Delete this file"?
"Delete this record?"

but you can not see what you have selected because the object you selected is under the dialog.

Even Windows; if you try to delete a single file, it will show the file name to be deleted but if you select two files, Windows asks you if you want to delete "these 2 elements" (a ListView in this dialog would be better, I think).
 
Last edited:
Upvote 0
Top