C# FileExplorer-选择目录文件xamarin android时出错

C# FileExplorer-选择目录文件xamarin android时出错,c#,android,xamarin,xamarin.android,C#,Android,Xamarin,Xamarin.android,我的应用程序中有一个文件资源管理器。单击按钮后,用户将导出一些文件。单击按钮时,它将启动文件资源管理器。我希望他们选择一个目标文件夹,从中导出此文件。我希望它能这样工作: 1.如果父目录是sd卡,他们可以选择将其保存在此处。如果不是,sd卡应显示任何子目录,如“下载/我的文档”等,他们可以选择这些文件夹中的任何一个。这应允许他们转到他们喜欢的任何较低级别的文件夹,或导航回并选择较高级别的文件夹 我的挑战是,当他们现在点击一个文件夹时,它会显示子目录。但是如果子目录本身没有子目录,点击它就会出现一

我的应用程序中有一个文件资源管理器。单击按钮后,用户将导出一些文件。单击按钮时,它将启动文件资源管理器。我希望他们选择一个目标文件夹,从中导出此文件。我希望它能这样工作:

1.如果父目录是sd卡,他们可以选择将其保存在此处。如果不是,sd卡应显示任何子目录,如“下载/我的文档”等,他们可以选择这些文件夹中的任何一个。这应允许他们转到他们喜欢的任何较低级别的文件夹,或导航回并选择较高级别的文件夹

我的挑战是,当他们现在点击一个文件夹时,它会显示子目录。但是如果子目录本身没有子目录,点击它就会出现一个空白屏幕。我也不知道如何选择我想要的文件夹。例如,如果我只想选择sd卡文件夹而不查看它

以下是我目前掌握的情况:

public override void OnListItemClick(ListView l, View v, int position, long id)
    {

        try{

            var folderSystemInfo = _adapter.GetItem(position);

            //Check if the directory has any sub directories

            if(folderSystemInfo.IsDirectory())
            {
                if(folderSystemInfo.GetDirectories() == null)
                {

                    // Do something with the file.  In this case we just pop some toast.
                    Log.Verbose("FileListFragment", "The file {0} was clicked.", folderSystemInfo.FullName);
                    Toast.MakeText(Activity, "You selected the Folder " + folderSystemInfo.FullName, ToastLength.Short).Show();

                    OnFileClick (folderSystemInfo);





                }else{

                    // Dig into this directory, and display it's contents-
                    RefreshFoldersList(folderSystemInfo.FullName); 

                }


            }

}catch(Exception ex)
        {


        }

        base.OnListItemClick(l, v, position, id);


    }


public void RefreshFoldersList(string directory)
    {


        IList<DirectoryInfo> visibleThings = new List<DirectoryInfo>();

        var dir = new DirectoryInfo(directory);



        try
        {
            foreach (var item in dir.GetDirectories().Where(item => item.IsVisible()))
            {

                visibleThings.Add(item);

            }
        }
        catch (Exception ex)
        {
            Log.Error("FileListFragment", "Couldn't access the directory " + _directory.FullName + "; " + ex);
            Toast.MakeText(Activity, "Problem retrieving contents of " + directory, ToastLength.Long).Show();
            return;
        }

        _directory = dir;

        _adapter.AddDirectoryContents(visibleThings);

        // If we don't do this, then the ListView will not update itself when the data set 
        // in the adapter changes. It will appear to the user that nothing has happened.
        ListView.RefreshDrawableState();

        Log.Verbose("FileListFragment", "Displaying the contents of directory {0}.", directory);
    }

我以前做过一些事情,这对我很有帮助,这正是我想要的,还有更多!我一直在实现文件的向后导航,而文件模式枚举刚刚解决了我所有的问题!非常感谢你!我非常感谢: