• Post Reply Bookmark Topic Watch Topic
  • New Topic

notifyDataSetChanged() with CustomAdapter and SQLite  RSS feed

 
simone giusti
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
After updating DB values I run this:



but nothing happens ...
 
Giovanni Montano
Ranch Hand
Posts: 428
7
Android Open BSD Slackware
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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 !!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!