MaterialChipsInput icon indicating copy to clipboard operation
MaterialChipsInput copied to clipboard

java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder{...

Open FranPR9 opened this issue 8 years ago • 5 comments

I get this: java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder{15b78fb4 position=4 id=-1, oldPos=-1, pLpos:-1 not recyclable(0)} whenever I try to: chipsInput.addChip(contact); of course contact class implements ChipInterface sometimes it do work, most of the time it gives me this error

FranPR9 avatar Aug 18 '17 23:08 FranPR9

Same here. In my case I still didn't see it working. I will investigate a bit, let's see if I find something.

mathias21 avatar Aug 22 '17 21:08 mathias21

Hi @FranPR9

I've fixed this by adding a method to ChipsInput class to add a list of chips. Then I forward it to the adapter and in the adapter it looks like this:

public void addChipsProgrammatically(List<ChipInterface> chipList){
        if(chipList != null){
            if(chipList.size() > 0) {
                int chipsBeforeAdding = getItemCount();
                for (ChipInterface chip : chipList) {
                    mChipList.add(chip);
                    mChipsInput.onChipAdded(chip, getItemCount());
                }

                // hide hint
                mEditText.setHint(null);
                // reset text
                mEditText.setText(null);

                notifyItemRangeChanged(chipsBeforeAdding, chipList.size());
            }
        }
    }

Most likely, the problem comes from notifying recyclerview about item added just after setting adapter. Could that be correct?

I hope this helps, maybe soon I will make another PR.

mathias21 avatar Aug 29 '17 15:08 mathias21

I didn't try your solution, but for me it worked to make the chipsinput visible until it has chips in its list. I think the problem has to do with the recycler being notified at a certain time for it to be resized. thanks @mathias21

FranPR9 avatar Oct 27 '17 16:10 FranPR9

solved this in a similar way by setting a minHeight in XML. stops the initial resizing to be messy I assume.

sameerjj avatar Nov 02 '17 22:11 sameerjj

I have the same problem and tried all of the above solutions but it has existed. Does anybody have other idea?

hamedhoseini avatar Jul 15 '19 12:07 hamedhoseini