Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adapters notifyDataSetChanged does not work

EDIT 2:

I did solve my problem, but i don't know how:S I was moving my code snippets a bit around, a suddenly it worked. Must have done something in the wrong order, but its weird, checked it many times. Thanks for you help, and sorry I can't post an answer ;)

Hi.

I have a list view which I'm trying to refresh to update it self when i add an element to the underlying array list.

Here is the code snippet:

private void addEvent() {
    arrlEvents.add( event );
    adptEvents.notifyDataSetChanged();
    updateSaveFile();
    filterList();
}

The arrlEvents is the underlying arraylist with the events, and im adding one event, trying to update the list view with notifyDataSetChanged(), but it doesnt work. Can anyone help?

Thanks for your time:)

EDIT: Here is the source code for the adapter:

private ArrayAdapter<Event> adptEvents;
adptEvents = new ArrayAdapter<Event>( EventCalendar.this, R.layout.list_items, arrlEvents );
like image 424
lands Avatar asked Jun 13 '26 22:06

lands


1 Answers

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:

public class ClassName extends ListActivity implements AdapterView.OnItemSelectedListener {

Global Variable:

CustomAdapter adapter;

in OnCreate():

adapter = new CustomAdapter(this,R.layout.layout_name,dataSet);
setListAdapter(adapter);

Whenever I need to notify

adapter.notifyDataSetChanged();
like image 145
blindstuff Avatar answered Jun 16 '26 11:06

blindstuff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!