尝试将android treeview实现为项目。但它显示
java.lang.ClassCastException:无法将java.lang.String强制转换为 com.example.ekatechhp.pkmapplication.holder.IconTreeItemHolder $ IconTreeItem 在com.example.ekatechhp.pkmapplication.holder.IconTreeItemHolder.createNodeView(IconTreeItemHolder.java:12)
从片段中调用IconTreeItemHolder.java。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_default, container, false);
ViewGroup containerView = (ViewGroup) rootView.findViewById(R.id.container);
TreeNode root = TreeNode.root();
TreeNode pkm = new TreeNode("Personal Knowledge Management");
TreeNode personal = new TreeNode("Personal");
TreeNode knowledge = new TreeNode("Knowledge");
TreeNode management = new TreeNode("Management");
pkm.addChildren(personal, knowledge, management);
root.addChild(pkm);
tView = new AndroidTreeView(getActivity(), root);
tView.setDefaultAnimation(true);
tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
tView.setDefaultViewHolder(IconTreeItemHolder.class);
tView.setDefaultNodeClickListener(nodeClickListener);
tView.setDefaultNodeLongClickListener(nodeLongClickListener);
containerView.addView(tView.getView());
if (savedInstanceState != null) {
String state = savedInstanceState.getString("tState");
if (!TextUtils.isEmpty(state)) {
tView.restoreState(state);
}
}
return rootView;
}