Android Xamarin TreeView nLevels [英] Android Xamarin TreeView nLevels
问题描述
我花了很多时间来探索如何在 Android Xamarin 中实现 TreeView,但不幸的是似乎没有任何例子可以说明这一点.
I spent so much time for discover how to implement TreeView in Android Xamarin, but unlucky seem not have any example say about that.
我尝试使用 ExpandableListView 但它只支持级别 2 类别.我需要有人会提供有关此内容的任何指南或有关此内容的示例.
I tried to use ExpandableListView but it only support to level 2 category. I need someone will have any guide to through this content or some example say about that.
目的是探索服务器上的文件夹!
非常感谢.
推荐答案
目的是探索服务器上的文件夹!
The purpose is explore the folders on server!
您可以使用绑定库导入一些 Java 库,例如 AndroidTreeView.
You can use Binding Library to import some java library for example like AndroidTreeView.
例如,我从这个项目创建了一个 .aar 库.然后像这样的代码:
For example, I created an .aar lib from this project. And then code for example like this:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
//create root
TreeNode root = TreeNode.InvokeRoot();
TreeNode parent = new TreeNode("parent");
TreeNode child0 = new TreeNode("ChildNode0");
TreeNode child1 = new TreeNode("ChildNode1");
TreeItem item = new TreeItem() { text = "abc" };
TreeNode child10 = new TreeNode(item).SetViewHolder(new MyHolder(this));
child1.AddChild(child10);
parent.AddChildren(child0, child1);
root.AddChild(parent);
AndroidTreeView atv = new AndroidTreeView(this, root);
LinearLayout rootlayout = FindViewById<LinearLayout>(Resource.Id.rootlayout);
rootlayout.AddView(atv.View);
rootlayout.Invalidate();
}
TreeItem
是这样创建的:
public class TreeItem : Java.Lang.Object
{
public string text;
}
而MyHolder
是这样的:
public class MyHolder : TreeNode.BaseNodeViewHolder
{
private Context mcontext;
public MyHolder(Context context) : base(context)
{
mcontext = context;
}
public override View CreateNodeView(TreeNode p0, Java.Lang.Object p1)
{
var inflater = LayoutInflater.FromContext(mcontext);
var view = inflater.Inflate(Resource.Layout.itemview, null, false);
TextView tv = view.FindViewById<TextView>(Resource.Id.itemtv);
var item = p1 as TreeItem;
tv.Text = item.text;
return view;
}
}
Here is the demo, you can find the .aar lib there.
这篇关于Android Xamarin TreeView nLevels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!