Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ContentObserver

I have a Cursor 'c' that generates a ListView. The Content Provider ensures that the ListView gets updated whenever the underlying data changes. However, I want to additionally make a call to another function to update my Header/Footer views everytime the listview is drawn.

How does one implement this with ContentObservers?

like image 469
Sameer Segal Avatar asked Oct 14 '22 22:10

Sameer Segal


1 Answers

public void listenChanges() {
 context.getContentResolver().registerContentObserver(CONTENT_URI, true,
 new MyContentObserver());
}

public class MyContentObserver extends android.database.ContentObserver {

 public MyContentObserver() {
  super(null);
 }

 @Override
 public void onChange(boolean selfChange) {
  super.onChange(selfChange);
  //Do all you need here
 }
}
like image 177
cement Avatar answered Oct 18 '22 02:10

cement