android - Strange behaviour ArrayList.remove(); -
i running issue , can't seem solve on own.
i trying remove item listview .remove(postion); , .notifydatasetchanged(position); removing wrong position.
here code
@override public view getview(int position, view convertview, viewgroup parent) { try { viewholder holder; final string[] parts; final string uuidbeacon; uuidbeacon = arrayl.get(position).getproximityuuid().tostring(); minorbeacon = arrayl.get(position).getminor(); rangebeacon = arrayl.get(position).getaccuracy(); parts = fetchtums(uuidbeacon).split("::"); if (convertview != null) { holder = (viewholder) convertview.gettag(); } else{ if(parts[0].equals("1")) { holder = new viewholder(convertview = inflater.inflate(r.layout.tupple_monitoring, null)); holder.beacon_image.setimagedrawable(gettumimage("http://127.0.0.1/uploads/face/" + parts[4])); holder.beacon_uuid.settext(parts[1]); holder.beacon_txpower.settext(string.valueof(position)); } if(parts[0].equals("0")) { holder = new viewholder(convertview = inflater.inflate(r.layout.tupple_monitoring, null)); holder.beacon_txpower.settext(string.valueof(position)); toremovestring = toremovestring + string.valueof(position) + "::"; } if(parts[2].equals("1")) { holder = new viewholder(convertview = inflater.inflate(r.layout.tupple_monitoring, null)); holder.beacon_image.setimagedrawable(gettumimage("http://127.0.0.1/uploads/face/" + parts[4])); holder.beacon_uuid.settext(parts[1]); holder.beacon_txpower.settext("hier misschien wat text?"); holder.beacon_row.setbackgroundcolor(color.parsecolor("#b6b6b6")); holder.image_lock.setvisibility(view.visible); } } if (arrayl.get(position).getproximityuuid() != null) list.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id ) { //list.setitemchecked(position, true); //view.setbackgroundcolor(color.blue); final string[] parts; parts = fetchtums(arrayl.get(position).getproximityuuid().tostring()).split("::"); if(parts[2].equals("1")){ pin(parts[3], parts[1]); } else{ if(parts[3] != null){ openpage(parts[3], "", parts[1]); } } } }); } catch (exception e) { e.printstacktrace(); } return convertview; }
the part above works fine list view 2 items position 0 , 1 , know items have correct postion write position in them in textview.
the function remove item is:
public void toremovefunc() { arrayl.remove(0); adapter.notifydatasetchanged(); }
it called on button click.
but happens strange when click button remove item position 1 , if click again remove item position 0. if change arrayl.remove(0); arrayl.remove(1); remove item position 1 , if click again crashes expected. want remove postion 0 , keep position 1.
your code working, after converting "convertview" not updating values.
viewholder holder; final string[] parts; final string uuidbeacon; uuidbeacon = arrayl.get(position).getproximityuuid().tostring(); minorbeacon = arrayl.get(position).getminor(); rangebeacon = arrayl.get(position).getaccuracy(); parts = fetchtums(uuidbeacon).split("::"); if (convertview != null) { holder = (viewholder) convertview.gettag(); } else{ holder = new viewholder(convertview = inflater.inflate(r.layout.tupple_monitoring, null)); } if(parts[0].equals("1")) { holder.beacon_image.setimagedrawable(gettumimage("http://127.0.0.1/uploads/face/" + parts[4])); holder.beacon_uuid.settext(parts[1]); holder.beacon_txpower.settext(string.valueof(position)); } if(parts[0].equals("0")) { holder.beacon_txpower.settext(string.valueof(position)); toremovestring = toremovestring + string.valueof(position) + "::"; } if(parts[2].equals("1")) { holder.beacon_image.setimagedrawable(gettumimage("http://127.0.0.1/uploads/face/" + parts[4])); holder.beacon_uuid.settext(parts[1]); holder.beacon_txpower.settext("hier misschien wat text?"); holder.beacon_row.setbackgroundcolor(color.parsecolor("#b6b6b6")); holder.image_lock.setvisibility(view.visible); }
Comments
Post a Comment