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

时间:2015-04-10 12:31:20

标签: c# android xamarin xamarin.android

我的应用程序中有一个文件浏览器。用户将点击一个按钮导出一些文件。单击该按钮时,它会启动文件浏览器。我希望他们选择一个目标文件夹,他们' ll导出这个文件。这就是我希望它工作的方式:

1.如果父目录是sdCard,他们可以选择将其保存在此处。如果没有,SD卡应显示任何子目录ed Downloads / My Documents等,他们可以选择任何这些文件夹。这应该允许他们去他们喜欢的任何较低级别的文件夹或导航回来并选择更高的文件夹。

我的挑战是,当他们现在点击一个文件夹时,它会显示子目录。但是如果子目录本身没有子目录,点击它就会出现空白屏幕。我也不知道如何选择我想要的folder.eg,如果我想只选择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);
    }

0 个答案:

没有答案