Skip to content
Sylvaner edited this page Aug 4, 2011 · 14 revisions

FileDialog, the easiest way to get an open file dialog box for Android developers.

What is it ? / Qu'est ce que c'est ?

FileDialog is a select file / directory dialog box for Android. She's very simple to integrate it to your project and really easy to use and configure.


FileDialog est une boite de dialogue pour sélectionner les fichiers / répertoires pour Android. Elle est très simple à intégrer à votre projet et vraiment facile à utiliser et configurer.

Screenshots / Captures d'écrans

Screenshot 1

Screenshot 2

How-to / Comment faire ?

Add it in your project / L'ajouter le à votre projet

Go to Source section and open file src/FileDialog.java Direct link

2 methods to integrate it in your project :

  1. Download the file and add it in your project.
  2. Create a class in your project called FileDialog.java. Copy / Paste the entire code.

Allez dans la section Source et ouvrez le fichier src/FileDialog.java Lien direct

2 méthodes pour l'intégrer à votre projet :

  1. Téléchargez le fichier et ajoutez le à votre projet.
  2. Créez un fichier dans votre projet nommé FileDialog.java. Copier / Coller le code en entier.

Use it / L'utiliser

An example is better than a long speech...


Un exemple vaut mieux qu'un long discours...

Select a directory

// Instantiate the class
FileDialog fd = new FileDialog(this);
// Add a listener for capture user action
fd.setListener(new FileDialog.ActionListener(){
    public void userAction(int action, String path)
    {
        // Test if user select a directory
        if (action == FileDialog.ACTION_SELECTED_DIRECTORY)
            doSomething(path);
    }});
// Show the dialog box
fd.selectDirectory();

// Instancie la classe
FileDialog fd = new FileDialog(this);
// Ajoute un listener pour capturer l'action d'un utilisateur
fd.setListener(new FileDialog.ActionListener(){
    public void userAction(int action, String path)
    {
        // Test si l'utilisateur a sélectionné un répertoire
        if (action == FileDialog.ACTION_SELECTED_DIRECTORY)
            doSomething(path);
    }});
// Afficher la boite de dialogue
fd.selectDirectory();

Select a file

// Instantiate the class
FileDialog fd = new FileDialog(this);
// Add a listener for capture user action
fd.setListener(new FileDialog.ActionListener(){
    public void userAction(int action, String filePath)
    {
        // Test if user select a file
        if (action == FileDialog.ACTION_SELECTED_FILE)
            doSomething(filePath);
    }});
// Show the dialog box
fd.selectFile();

With selectFile method, user can create new file and new directories. For strict select file, use selectFileStrict


// Instancie la classe
FileDialog fd = new FileDialog(this);
// Ajoute un listener pour capturer l'action d'un utilisateur
fd.setListener(new FileDialog.ActionListener(){
    public void userAction(int action, String filePath)
    {
        // Test si l'utilisateur a sélectionné un fichier
        if (action == FileDialog.ACTION_SELECTED_FILE)
            doSomething(filePath);
    }});
// Afficher la boite de dialogue
fd.selectFile();

Avec la méthode selectFile, l'utilisateur peut créer un nouveau fichier et des nouveaux répertoire. Pour une sélection de fichier stricte, utilisez selectFileStrict

Advanced functions / Fonctions avancées

Suggest a filename / Suggérer un nom de fichier

When user select a file, he can create a new file an you can suggest a name :

fd.setSuggestedFileName("file.sav");

Quand un utilisateur sélectionne un fichier, il peut créer un nouveau fichier et vous pouvez lui suggérer un nom :

fd.setSuggestedFileName("fichier.sav");

Change default path / Changer le répertoire par défaut

Default path is /sdcard/, you can change it :

fd.setPath("/sdcard/save");

Le répertoire par défaut est /sdcard/, vous pouvez le changer :

fd.setPath("/sdcard/sauvegarde");

Returned actions

When user do an action, dialog box call the listener and return an action :

Action Data
FileDialog.ACTION_SELECTED_FILE Path of the file
ACTION_SELECTED_DIRECTORY Path of the directory
ACTION_CANCEL null

Quand un utilisateur fait une action, la boite de dialogue appelle le listener et renvoie une action :

Action Data
FileDialog.ACTION_SELECTED_FILE Chemin du fichier
ACTION_SELECTED_DIRECTORY Chemin du répertoire
ACTION_CANCEL null