android - Data does not display properly in Adapter when Removing/Adding -


i running issue use 2 separate adapters, , 2 seperate gridviews (1 adapter, 1 gridview), , removing items either adapter, , adding other if item pressed, , vice versa.

when press , item in 1 gridview, item removed respective adapter , put other gridview , respective adapter. issue seems way data being stored (potentially) because when add item adapter, icons totally different should be.

note: noticed happens items pressed after first 1 pressed. first items data added/removed properly. however, have found when item takes on first position of associated adapter, have icon of removed item.

what can ensure data stays consistent item pressed?.

adapter class

public class miscchargeoptionsadapter extends arrayadapter<carclasssettingdetails> {  private layoutinflater inflater;  public miscchargeoptionsadapter(context context, list<carclasssettingdetails> settinglist) {     super(context, r.layout.misc_charge_option_layout, r.id.option_grid_option_text, settinglist);     inflater = layoutinflater.from(context); }  @suppresslint("inflateparams") @override public view getview(int position, view convertview, viewgroup parent) {     carclasssettingdetails settingsdetails = this.getitem(position);     viewholder vh;     if (convertview == null) {         vh = new viewholder();         convertview = inflater.inflate(r.layout.misc_charge_option_layout, null);         vh.optiontext = (textview) convertview.findviewbyid(r.id.option_grid_option_text);         vh.settingview = (settingview) convertview.findviewbyid(r.id.option_grid_option_icon);         convertview.settag(vh);     } else {         vh = (viewholder) convertview.gettag();     }      vh.optiontext.settext(settingsdetails.getname());      vh.settingview.seticon(settingsdetails.geticon());     vh.settingview.seticonselected(settingsdetails.geticonselected());     vh.settingview.setviewbackgroundcolor(settingsdetails.getviewbackgroundcolor());     vh.settingview.setbackgroundcolorselected(settingsdetails.getbackgroundcolorselected());     vh.settingview.setamountbackgroundcolor(settingsdetails.getamountbackgroundcolor());     vh.settingview.setamounttextcolor(settingsdetails.getamounttextcolor());     vh.settingview.setvalue(settingsdetails.getvalue());     vh.settingview.setignoresetstate(true);     vh.settingview.settag(position);     return convertview; }  class viewholder {     private textview optiontext;     private settingview settingview;      /*      public viewholder(textview optiontext, settingview settingview) {                 this.optiontext = optiontext;                 this.settingview = settingview;             }*/      public textview getoptiontext() {         return optiontext;     }      public settingview getsettingview() {         return settingview;     } } 

}

how adapters set

selectedadapter = new carclassoptionsadapter(getactivity(), selectedsettingslist);   unselectedadapter = new carclassoptionsadapter(getactivity(), unselectedsettingslist);       gridselected.setadapter(selectedadapter);      gridselected.setonitemclicklistener(this);     gridunselected.setadapter(unselectedadapter);      gridunselected.setonitemclicklistener(this); 

how adding/removing items adapters

@override public void onitemclick(adapterview<?> parent, view view, int position, long id) {     if (parent.getadapter() == selectedadapter) {         //todo: add dialogs         unselectedadapter.add(selectedadapter.getitem(position));         unselectedadapter.notifydatasetchanged();         selectedadapter.remove(selectedadapter.getitem(position));         selectedadapter.notifydatasetchanged();      } else if (parent.getadapter() == unselectedadapter) {         //todo: add dialogs         selectedadapter.add(unselectedadapter.getitem(position));         selectedadapter.notifydatasetchanged();         unselectedadapter.remove(unselectedadapter.getitem(position));         unselectedadapter.notifydatasetchanged();     } } 

this how carclasssettingdetails class being populated

private void addmiscchargeselected(ws_miscchargeselected miscchargeselected, boolean isselected) {      try {         carclasssettingdetails settingdetails = new carclasssettingdetails(getactivity());          if (miscchargeselected.getcode() != null && !miscchargeselected.getcode().equals("")) {             settingdetails.setcode(miscchargeselected.getcode());         }          if (miscchargeselected.getname() != null && !miscchargeselected.getname().equals("")) {             settingdetails.setname(miscchargeselected.getname());         }          if (miscchargeselected.geticon() != null && !miscchargeselected.geticon().equals("")) {             bitmap settingicon = iconutils.loadicon(getactivity(), miscchargeselected.geticon());             bitmap settingiconselected = iconutils.loadicon(getactivity(), miscchargeselected.geticon());             settingdetails.seticon(settingicon);             settingdetails.seticonselected(settingiconselected);         }         if (miscchargeselected.getvalue() != null && !miscchargeselected.getvalue().equals("")) {             settingdetails.setvalue(ws_value.fromint(integer.parseint(miscchargeselected.getvalue())));             settingdetails.setamountbackgroundcolor(color.parsecolor("#00ffffff"));             settingdetails.setamounttextcolor(color.parsecolor("#ff00428e"));         } else {             settingdetails.setvalue(null);         }         settingdetails.setviewbackgroundcolor(color.parsecolor("#ffd4d4d4"));         settingdetails.setbackgroundcolorselected(color.parsecolor("#ff616161"));          if (isselected) {             //todo: add top adapter             selectedsettingslist.add(settingdetails);         } else {             //todo: add bottom adapter                    unselectedsettingslist.add(settingdetails);         }     } catch (exception e) {         log.e(tag, e.getmessage());     } } 

misc charge details

public class miscchargesettingdetails {     private context context;     private string code;     private string name;     private string description;     private bitmap icon = null;     private bitmap iconselected = null;     private ws_value value = null;     private int amountbackgroundcolor, amounttextcolor, viewbackgroundcolor, backgroundcolorselected;      public miscchargesettingdetails(context context) {         this.context = context;     }      protected context getcontext() {         return context;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public string getdescription() {         return description;     }      public void setdescription(string description) {         this.description = description;     }      public bitmap geticon() {         return icon;     }      public void seticon(bitmap icon) {         this.icon = icon;     }      public bitmap geticonselected() {         return iconselected;     }      public void seticonselected(bitmap iconselected) {         this.iconselected = iconselected;     }      public ws_value getvalue() {         return value;     }      public void setvalue(ws_value value) {         this.value = value;     }      public int getamountbackgroundcolor() {         return amountbackgroundcolor;     }      public void setamountbackgroundcolor(int amountbackgroundcolor) {         this.amountbackgroundcolor = amountbackgroundcolor;     }      public int getamounttextcolor() {         return amounttextcolor;     }      public void setamounttextcolor(int amounttextcolor) {         this.amounttextcolor = amounttextcolor;     }      public int getviewbackgroundcolor() {         return viewbackgroundcolor;     }      public void setviewbackgroundcolor(int viewbackgroundcolor) {         this.viewbackgroundcolor = viewbackgroundcolor;     }      public int getbackgroundcolorselected() {         return backgroundcolorselected;     }      public void setbackgroundcolorselected(int backgroundcolorselected) {         this.backgroundcolorselected = backgroundcolorselected;     }      public string getcode() {         return code;     }      public void setcode(string code) {         this.code = code;     } } 

can show place you're populating list of settingviews? data model (settingview) extends view? not best idea use view object model..


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -