Android A collection problem led to have to say the story

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.