AndroidTreeView icon indicating copy to clipboard operation
AndroidTreeView copied to clipboard

who the treeview's parent

Open wangxiaowei000 opened this issue 8 years ago • 3 comments

The specified child already has a parent. You must call removeView() on the child's parent first. I want to remove the existing data and Add new data,but has a Error

wangxiaowei000 avatar Jun 08 '17 09:06 wangxiaowei000

Probably I have a different problem, but the bahavior is the same:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

I'm trying to create a context menu for the tree view, so I used registerForContextMenu(tView.getView()), but when the app runs this error is thrown.

The code looks like this:

// Created the tree (root node)
LinearLayout layout = new LinearLayout(getActivity());
AndroidTreeView tView = new AndroidTreeView(getActivity(), root);
layout.addView(tView.getView());
registerForContextMenu(tView.getView());

So, how can I bind context menu to the AndroidTreeView? Or, am I only able to use tView.setDefaultNodeLongClickListener() and create a dialog myself?

Thanks in advance :)

renyuneyun avatar Jun 11 '17 23:06 renyuneyun

Hello Folks,

I find the same issue while adding AndroidTreeView to RelativeLayout. Is there any Solution ?

Any Help would be appreciated.

DipaliShah avatar Jun 26 '17 11:06 DipaliShah

I had the same problem. What I was doing wrong was I was setting the same viewHolder on each node instead of instantiating a new one for each. This meant it was trying to attach the same view to all the nodes. So basically, don't do this:

MyViewHolder myViewHolder = new MyViewHolder();
for(TreeNode node : nodes) {
    node.setViewHolder(myViewHolder);
}

Do this:

for(TreeNode node : nodes) {
    MyViewHolder myViewHolder = new MyViewHolder();
    node.setViewHolder(myViewHolder);
}

Hopefully, this helps someone having a similar problem.

vssh avatar Nov 07 '17 21:11 vssh