我使用此lib。我想为任何孩子添加图标。但我不知道我怎么做。请帮助我。感谢任何身体。我读取样本但是..这是我的代码。请阅读链接
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TreeNode root = TreeNode.root();
final TreeNode parent = new TreeNode("Melk");
final TreeNode child0 = new TreeNode("Build_1");
TreeNode child1 = new TreeNode("Build_2");
TreeNode child_1 = new TreeNode("Aparteman_1");
TreeNode child_3 = new TreeNode("Aparteman_2");
TreeNode child_4 = new TreeNode("Senfi_1");
TreeNode child_5 = new TreeNode("Senfi_2");
child_1.addChildren(child_4, child_5);
child0.addChildren(child_1, child_3);
parent.addChildren(child0, child1);
root.addChild(parent);
Button del = (Button) findViewById(R.id.del);
parent.setClickListener(new TreeNode.TreeNodeClickListener() {
@Override
public void onClick(TreeNode node, Object value) {
Toast.makeText(getApplicationContext(),"",Toast.LENGTH_LONG).show();
}
});
LinearLayout containerView = (LinearLayout) findViewById(R.id.m);
AndroidTreeView tView = new AndroidTreeView(getApplicationContext(), root);
containerView.addView(tView.getView());
}
}
发表编辑。我需要你的帮助。
答案 0 :(得分:0)
你必须使用自定义适配器,因为它用于默认的android listview唯一的区别是扩展TreeNode.BaseNodeViewHolder并覆盖createNodeView 这是一个结构
public class MyHolder extends TreeNode.BaseNodeViewHolder<IconTreeItem> {
...
@Override
public View createNodeView(TreeNode node, IconTreeItem value) {
final LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(R.layout.layout_profile_node, null, false);
TextView tvValue = (TextView) view.findViewById(R.id.node_value);
tvValue.setText(value.text);
return view;
}
public static class IconTreeItem {
public int icon;
public String text;
}
}
有关更多信息,本教程将帮助您了解如何使用自定义适配器 https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView