android - notifyDataSetChanged() not working with custom adapter -


i making edit on list of custom objects, notifydatasetchanged() not updating list. setup: fragment displaying list of states. state edited in dialog fragment , applydialogstate() called on edit action.

void applydialogstateedit(int id, string name) {         // apply stateeditdialog fragment edits directly mstates         state state = mstates.get(id);         state.name = name;          // write state change saves         getactivity().getsharedpreferences("mystates", context.mode_private).edit().                 putstring(state.date, mgson.tojson(state)).commit();          mstateadapter.notifydatasetchanged();     } 

things have looked at:

  • i confirmed method called.

  • sharedpreferences updated - changes visible once activity reloaded.

  • there doesn't seem reference problem.

  • after notifydatasetchanged() called, see debugger internal state list in custom adapter correspond mstates updated correctly...

  • in other case notifydatasetchanged() working... i.e.

    public void deleteallstates() {     getactivity().getsharedpreferences("mystates", context.mode_private).edit().clear().commit();     mstates.clear();     if (mstateadapter != null) {         mstateadapter.notifydatasetchanged();     } } 

my custom array adapter:

class stateadapter extends arrayadapter<state> {     context context;     arraylist<state> states;     int row_res;     stateadapter(context context, int itemviewid, arraylist<state> states) {         super(context, itemviewid, states);         this.context = context;         this.row_res = itemviewid;         this.states = states;     } @override public view getview(int pos, view convertview, viewgroup parent) {     view row;     if (convertview == null) {         layoutinflater inflater = ((activity)context).getlayoutinflater();         row = inflater.inflate(row_res, null);         textview tv = (textview) row.findviewbyid(r.id.state_description);         tv.settext(states.get(pos).name + "; " + states.get(pos).date);     } else {         row = convertview;     }     return row; } 

any ideas?

edit1 - extending arrayadapter:

class stateadapter extends arrayadapter<state> {     context context;     arraylist<state> states;     int row_res;     stateadapter(context context, int itemviewid, arraylist<state> states) {         super(context, itemviewid, states);         this.context = context;         this.row_res = itemviewid;         this.states = states;     } 

edit2 - setting array adapter on list:

 @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         log.e(tag, "oncreateview: called");         // inflate layout fragment         view root = inflater.inflate(r.layout.fragment_state_list, null, false);         mroot = root;         listview lv = (listview) root.findviewbyid(r.id.state_list);         if (mstates != null) {             mstateadapter = new stateadapter(getactivity(), r.layout.state_row, mstates);             lv.setadapter(mstateadapter);             lv.setonitemclicklistener(new listview.onitemclicklistener() {                 @override                 public void onitemclick(adapterview<?> parent, view view, int position, long id) {                     try {                         log.e(tag, "onitemclick: position clicked - " + position);                         ((statelistinterface) getactivity()).onstateselected(mstateadapter.getitem(position));                     } catch (exception e) {                         // nothing                     }                 }             }); 


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -