介绍一个android开源文件选择对话框:android-file-dialog
2012-09-01 00:26
507 查看
链接见此:http://code.google.com/p/android-file-dialog/
源码在这里:http://code.google.com/p/android-file-dialog/source/browse/#svn%2Ftrunk%2FFileExplorer%2Fsrc%2Fcom%2Flamerman
谢谢作者的无私贡献,虽然功能简单,但能节省些许开发时间。同时还能应付一些常见的文件选择功能需求,大家可根据自己的项目需求在上面作相应更改。
使用说明:
The dialog is created like this:
Here "/sdcard" is the start path where the file dialog will open. REQUEST_SAVE is your integer constant, it will then be transmitted to onActivityResult;
CAN_SELECT_DIR - possibility to select directories FORMAT_FILTER - files filter. If file name ends with one of filters the file will be displayed.
When user selects a file or just goes back not selected anything, the activity closes, calling the standard onActivityResult method:
The result code will be Activity.RESULT_OK if user has selected something and Activity.RESULT_CANCELED if he just pressed the BACK button not selecting anything. You can retrieve the filepath from the intent:
If for some reason the words startActivityForResult and onActivityResult are not familiar to you, just read documentation about them. In short, an activity is created and when it exits a handler is called. In this handler you can get the filepath.
You can add one more parameter to the Intent: SelectionMode.MODE_OPEN or SelectionMode.MODE_CREATE
SelectionMode.MODE_OPEN will make the NEW button disabled. So user can only select existing files
源码在这里:http://code.google.com/p/android-file-dialog/source/browse/#svn%2Ftrunk%2FFileExplorer%2Fsrc%2Fcom%2Flamerman
谢谢作者的无私贡献,虽然功能简单,但能节省些许开发时间。同时还能应付一些常见的文件选择功能需求,大家可根据自己的项目需求在上面作相应更改。
使用说明:
Usage principles
The dialog is created like this:Intent intent = new Intent(getBaseContext(), FileDialog.class); intent.putExtra(FileDialog.START_PATH, "/sdcard"); //can user select directories or not intent.putExtra(FileDialog.CAN_SELECT_DIR, true); //alternatively you can set file filter //intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { "png" }); startActivityForResult(intent, REQUEST_SAVE);
Here "/sdcard" is the start path where the file dialog will open. REQUEST_SAVE is your integer constant, it will then be transmitted to onActivityResult;
CAN_SELECT_DIR - possibility to select directories FORMAT_FILTER - files filter. If file name ends with one of filters the file will be displayed.
When user selects a file or just goes back not selected anything, the activity closes, calling the standard onActivityResult method:
public synchronized void onActivityResult(final int requestCode, int resultCode, final Intent data) { if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_SAVE) { System.out.println("Saving..."); } else if (requestCode == REQUEST_LOAD) { System.out.println("Loading..."); } String filePath = data.getStringExtra(FileDialog.RESULT_PATH); } else if (resultCode == Activity.RESULT_CANCELED) { Logger.getLogger(AccelerationChartRun.class.getName()).log( Level.WARNING, "file not selected"); } }
The result code will be Activity.RESULT_OK if user has selected something and Activity.RESULT_CANCELED if he just pressed the BACK button not selecting anything. You can retrieve the filepath from the intent:
data.getStringExtra(FileDialog.RESULT_PATH);
If for some reason the words startActivityForResult and onActivityResult are not familiar to you, just read documentation about them. In short, an activity is created and when it exits a handler is called. In this handler you can get the filepath.
You can add one more parameter to the Intent: SelectionMode.MODE_OPEN or SelectionMode.MODE_CREATE
intent.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
SelectionMode.MODE_OPEN will make the NEW button disabled. So user can only select existing files
相关文章推荐
- 介绍一个android开源文件选择对话框:android-file-dialog
- SAP ABAP编程 选择文件对话框 CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
- SAP ABAP编程 选择文件对话框 CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
- Android开发笔记(二十三)文件对话框FileDialog
- asp.net 点击一个按钮弹出对话框选择文件然后选择文件完成之后就自动上传文件 input(file)
- 如何在JSP页面中通过一个按钮,在对话框中选择一个目录而不是选择一个文件;input type=file只能选择一个文件,我想选择一个目录;做不出来项目经理要扣奖金的...............
- 【C#】文件选择对话框OpenFileDialog与下列列表ComboBox
- C# OpenFileDialog 打开/选择文件对话框
- 文件选择对话框filedialog,OpenFileDialog,FolderBrowserDialog
- ajaxFileupload只能选择一个文件问题解决
- Android 实现 选择文件对话框
- 如何用c#打开文件夹并选择文件夹内的一个文件 open folder and select file
- Android基于开源项目的WheelView的时间、地址联动选择对话框【转】
- aFileChooser:兼容android2.1+的文件选择器
- OpenFileDialog 打开文件对话框
- Android UI开发第十九篇——介绍一个开源的gifview——Android显示GIF动画
- unity----OpenFileDialog打开选择对话框
- 用openFileDialog选择多个文件
- android 实现点击输入框弹出日期选择对话框(DatePickerDialog)
- Glide :一个android平台上的快速和高效的开源的多媒体资源管理库, 提供 多媒体文件的压缩,内存和磁盘缓存, 资源池的接口