Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

How to delete an entry in a table from a recyclerview

 
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a basic app where i can add customers to a database and display them on another screen, i have set up everything using recyclerview and card views to display the customers and that works fine, but im not sure how i set it up so that i can delete the customers. i have added a button to each of the customers that will be used to delete them.

customer database


adapter


customer class


any help would be appreciated
 
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here the ideas:

1. Create a delete function (Eg: removeItem ) in CustomerDB class.
2. When the delete button is clicked, pass the id to removeItem method.
3. Execute the delete query in removeItem method.
4. Refresh recyclerView.
 
adrian rowlands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randy Tong wrote:Here the ideas:

1. Create a delete function (Eg: removeItem ) in CustomerDB class.
2. When the delete button is clicked, pass the id to removeItem method.
3. Execute the delete query in removeItem method.
4. Refresh recyclerView.



app crashes when i add a onclicklistener for the button and go to that screen
 
Randy Tong
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
paste your latest code and the stacktrace.
 
adrian rowlands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[

Randy Tong wrote:paste your latest code and the stacktrace.






added that the customer class along with the deleteCustomer function in the customerdb



when i go onto the screen it just gives me a white screen then goes back to log in screen

stack trace



so obviously something is wrong with the deleCustomer method, im probably way off the right code for it lol
 
Randy Tong
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need to call deleteCustomer twice ? Between, don't forget to post your stacktrace.
 
adrian rowlands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randy Tong wrote:Why do you need to call deleteCustomer twice ? Between, don't forget to post your stacktrace.


noticed i had it in there twice after posting, deleted it now
the second one was what showed up in the stack trace
 
Randy Tong
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

adrian rowlands wrote:the second one was what showed up in the stack trace


No, that's not the stacktrace. The stacktrace is the error message which made your app  crashed. You can find the stacktrace in logcat window (if you using Android Studio).
 
adrian rowlands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randy Tong wrote:

adrian rowlands wrote:the second one was what showed up in the stack trace


No, that's not the stacktrace. The stacktrace is the error message which made your app  crashed. You can find the stacktrace in logcat window (if you using Android Studio).



i get these errors in the log cat when i run it

2021-04-30 13:53:36.187 22070-22070/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2021-04-30 13:53:36.188 22070-22070/? E/Zygote: accessInfo : 1
2021-04-30 13:53:36.215 22070-22070/? E/andsflooringap: Unknown bits set in runtime_flags: 0x8000
these warnings
2021-04-30 13:54:42.472 23420-23420/com.example.rowlandsflooringapp W/andsflooringap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-04-30 13:54:42.473 23420-23420/com.example.rowlandsflooringapp W/andsflooringap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-04-30 13:54:42.620 23420-23804/com.example.rowlandsflooringapp W/Gralloc3: mapper 3.x is not supported
 
Randy Tong
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'r pasting log message instead of the error.The error should look similar to this
crash-log.png
[Thumbnail for crash-log.png]
 
adrian rowlands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randy Tong wrote:I think you'r pasting log message instead of the error.The error should look similar to this




 
Randy Tong
Rancher
Posts: 582
9
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic