我有一个小模块来列出android中的文件夹结构。如果用户单击一个节点(此节点是图标集合,即文件夹图标,箭头图标等),则会列出所选文件夹中的子文件夹。现在我想在一开始就显示根文件夹的子文件夹。现有的只显示根文件夹。如果我可以在一开始就调用节点项的单击侦听器,我可以轻松地完成此操作。我怎么能这样做。
public static void callFolderSection(Context context,int mailBox,Fragment fragment)
{
AndroidTreeView tView;
//selectedMailBox = mailBox;
final Dialog dialog = new Dialog(context);
dashContext = context;
fragmentName = fragment;
selectedMailBox = mailBox;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setContentView(R.layout.layout_default);
((DashboardActivity) context).dialogFolder = dialog;
ViewGroup containerView = (ViewGroup) dialog.findViewById(R.id.container);
MailServices mailServices = new MailServices();
ArrayList<FolderSection> folderSectionList ;
folderSectionList = mailServices.listFoldersAndSections("0",mailBox);
//获取根文件夹
TreeNode root = TreeNode.root();
TreeNode computerRoot = new TreeNode(new IconTreeItemHolder.IconTreeItem(GlobalVariables.getGsLoginProjectNo(),"0","0",fragment,0,0,folderSectionList.get(0).get_childCount()));
for (int count = 0;count < folderSectionList.size();count++)
{
TreeNode treeNode = new TreeNode(new IconTreeItemHolder.IconTreeItem(folderSectionList.get(count).get_title(),Integer.toString(folderSectionList.get(count).get_int_Key()),Integer.toString(folderSectionList.get(count).get_int_parent()),fragmentName,folderSectionList.get(count).get_isSmartSection(),folderSectionList.get(count).get_itemCount(),folderSectionList.get(count).get_childCount()));
computerRoot.addChildren(treeNode);
}
root.addChildren(computerRoot);
tView = new AndroidTreeView(context, root);
tView.setDefaultAnimation(true);
tView.setDefaultContainerStyle(R.style.TreeNodeStyleCustom);
tView.setDefaultViewHolder(IconTreeItemHolder.class);
//设置点击监听器
tView.setDefaultNodeClickListener(nodeClickListener);
containerView.addView(tView.getView());
Window window = dialog.getWindow();
if (GlobalVariables.getGsDevice().equals("tab")) {
dialog.show();
}
//点击监听器
private static TreeNode.TreeNodeClickListener nodeClickListener = new TreeNode.TreeNodeClickListener() {
@Override
public void onClick(TreeNode node, Object value) {
IconTreeItemHolder.IconTreeItem item = (IconTreeItemHolder.IconTreeItem) value;
((DashboardActivity) dashContext).folderIntKey = Integer.parseInt(item.int_Key);
MailServices mailServices = new MailServices();
DocumentServices documentServices = new DocumentServices();
try {
if (Integer.parseInt(item.int_Key) != 0) {
if (node.getChildren().size() == 0) {
ArrayList<FolderSection> folderSectionList;
if(((DashboardActivity) dashContext).isFolderDoc)
{
folderSectionList = documentServices.listFoldersAndSections(item.int_Key);
}
else
{
folderSectionList = mailServices.listFoldersAndSections(item.int_Key, selectedMailBox);
}
for (int count = 0; count < folderSectionList.size(); count++) {
TreeNode treeNode = new TreeNode(new IconTreeItemHolder.IconTreeItem(folderSectionList.get(count).get_title(), Integer.toString(folderSectionList.get(count).get_int_Key()), Integer.toString(folderSectionList.get(count).get_int_parent()), fragmentName,folderSectionList.get(count).get_isSmartSection(),folderSectionList.get(count).get_itemCount(),folderSectionList.get(count).get_childCount()));
node.addChildren(treeNode);
}
}
}
}
catch (Exception ex)
{
}
}
};
编辑:编辑代码snipets以适当的方式工作。
答案 0 :(得分:0)
试试这个
nodeClickListener.onClick(node,value);
Node =您想要的节点。
值=它具有的值。
编辑:我读了库的代码,也许你可以使用
expandNode(TreeNode node)
答案 1 :(得分:0)
使用 performClick()方法。
因为你有根视图。