• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

notifyDataSetChanged() with CustomAdapter and SQLite

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to update Listview when database is updated.

Custom Adapter


DataModel:



DB Layer:



In mainactivity I have this method to update LISTVIEW:



When Database is updated (see DBLayer Class) I would like to refresh LISTVIEW in mainActivity view ...

I tried ... with no results ...

Thanks.
 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:Too difficult as for beginning. Moving to Java in General. This post will self dissapear in few days.



Maybe too difficult for me !!
thanks.
 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After updating DB values I run this:



but nothing happens ...
 
Ranch Hand
Posts: 600
11
Android Python Open BSD VI Editor Slackware
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as for the other post, should be solved with CursorLoaders




simone giusti wrote:I am not able to update Listview when database is updated.

Custom Adapter


DataModel:



DB Layer:



In mainactivity I have this method to update LISTVIEW:



When Database is updated (see DBLayer Class) I would like to refresh LISTVIEW in mainActivity view ...

I tried ... with no results ...

Thanks.

 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Giovanni Montano wrote:as for the other post, should be solved with CursorLoaders

simone giusti wrote:

Maybe this is too difficult for me ...

I find a loto of examples suggesting to use notifyDataSetChanged but it has no effect. Maybe I choose the wrong place to put it.

Any suggestions ?

 
Marshal
Posts: 4173
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One solution would be to have the ListAdapter register a listener with the data source so that whenever the data source is modified, it would call the listener, and the listener would then call the notifyDataSetChanged method.  For example:
 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:One solution would be to have the ListAdapter register a listener with the data source so that whenever the data source is modified, it would call the listener, and the listener would then call the notifyDataSetChanged method.  For example:



Thanks Ron,
what I did not understand is why I can't simply call notifyDataSetChanged once db is updated to refresh listview.




DB is updated in DBhelper.class




Thanks
 
Ron McLeod
Marshal
Posts: 4173
555
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One problem is the you are calling your update method on a new instance of MainActivity, rather than the launched MainActivity instance:
If you want to involve the MainActivity in updating the list view, then pass AsyncTask a reference to use to inform the MainActivity that the list data set has changed.  Here's an example:
 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:One problem is the you are calling your update method on a new instance of MainActivity, rather than the launched MainActivity instance:



Thank Ron ... helpful !!
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic