Don't say anything, look at the picture first, then tell you the need!
Skills can only add three items, if you choose more than three to give hints, the selection can be clicked again is deleted, this is certainly not difficult, but do find a problem, in this record, my practice is to define a set, and then when the user clicks to determine whether this is in the collection if it is deleted in the collection, If you do not add it in the collection, and then Adapter.notifydatasetchanged () is finished, first I wrote the Click event related logic:
@Overridepublic void Onitemclick (adapterview<?> arg0, View arg1, int position, long Arg3) {if ( Clickpositions.contains (position)) {//If it is included, delete count--;clickpositions.remove (position);} Else{count++;if (count>3) {showtoast.show ("add up to three items oh"); return;} Clickpositions.add (position);} Adapter.notifydatasetchanged ();}
And then when you want to delete it, it will quote the corner mark out of bounds! Really miss Qi sister Ah, and later found that the list collection is an integer type, and I romove the time is to pass position directly into the, this will think you are delete the corresponding value in the first collection, And actually you just want to delete the item corresponding to the position,
Solution: Wrapping position into objects can be a word clickpositions.remove (new Integer (position));
Record it again!
Android A collection problem led to have to say the story