Adapters Notifydatasetchanged Does Not Work
Solution 1:
I have seen that sometimes it just randomly doesnt notify the adapter.
Try using adptEvents as protected or public on a global scope.
I have found that when that doesnt work. You can just re set the adapter again, just substitute the notifyDataSetChanged() for:
adptEvents = new ArrayAdapter<Event>( EventCalendar.this, R.layout.list_items, arrlEvents );
Edit:
Heres a code snipper from an App I wrote that works.
Class definition:
publicclassClassNameextendsListActivityimplementsAdapterView.OnItemSelectedListener {
Global Variable:
CustomAdapter adapter;
in OnCreate():
adapter = newCustomAdapter(this,R.layout.layout_name,dataSet);
setListAdapter(adapter);
Whenever I need to notify
adapter.notifyDataSetChanged();
Solution 2:
There is no persistent link between arrlEvents and the adptEvents.... the latter simply initialises itself with the elements from the former. adptEvents has no way to know when arrlEvents changes.
To add new items you should call adptEvents.add(event) and not bother calling notifyDataSetChanged() explicitly, since ArrayAdapter.add() does that for you automatically.
Post a Comment for "Adapters Notifydatasetchanged Does Not Work"