I'm working on an Android application, and when I attempt to display large amounts of data in a listview
, I receive the following error:
01-24 18:06:32.214:
INFO/System.out(9244):
EX:Observer android.widget.AdapterView$AdapterDataSetObserver@43c9b200
was not registered.
i got this error too.
in my case this exception (Observer * was not registered.) was thrown because i called
setAdapter(Adapter)
multiple times.
for example:
MyAdapter (extends BaseAdapter) vla;
ListView lv;
for (int i = 0; i < 2; i++) {
vla.clear();
vla.add(tv);
lv.setAdapter(vla);
}
The fix here is to place
v.setAdapter(vla);
outside the loop, thereby avoiding multiple calls.
after fix no more exception throws.
best regards, flood. (fldr atincircle mail dot ru)
I faced the same problem and it turned out to be a threading issue. Multiple threads were calling setAdapter
which does not seem to be threadsafe. After making sure that all setAdapter
calls are done on the same thread, the problem was solved.
What worked nicely for me, was to force my code to change it only on the UI thread:
runOnUiThread(new Runnable() {
@Override
public void run() {
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rc_view);
recyclerView.setAdapter(new MyAdapter(items));
}
});
I've ran into this problem multiple times when dealing with listviews. If you're using a custom adapter with an edit text involved, you'll want to do a clearFocus() before you refresh the adapter. Observer not registered is caused by the listview deleting a child that has focus on the activity
How I do it: this is the view holder for my custom adapter
class viewHolder {
public viewHolder() {
views = new ArrayList<viewInfo>();
}
public int position;
public ArrayList<viewInfo> views;
public View view;
}
After which i invoke an unfocusAll() which consists of:
public void unFocusAll() {
viewHolder holder = (viewHolder) v.getTag();
if (holder != null) {
holder.view.clearFocus();
}
}
So before you invoke your listview you have to do
CustomAdapter aa = new CustomAdapter();
if (aa != null) {
aa.unFocusAll();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With