Skip to content

javieranton-zz/cn1-filechooser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Filechooser for Codename One

Supported Platforms:

  • Javascript
  • iOS
  • Android
  • Simulator (JavaSE)

Installation

  1. Add CN1FileChooser.cn1lib to your project's lib directory and refresh your cn1libs.
  2. If deploying to iOS, you'll need to make sure that your App ID includes iCloud support, and you must associate with at least one iCloud container. See iOS setup instructions here

Code Sample:

if (FileChooser.isAvailable()) {
    FileChooser.showOpenDialog(".xls, .csv, text/plain", e2-> {
        String file = (String)e2.getSource();
        if (file == null) {
            hi.add("No file was selected");
            hi.revalidate();
        } else {
           String extension = null;
           if (file.lastIndexOf(".") > 0) {
               extension = file.substring(file.lastIndexOf(".")+1);
           }
           if ("txt".equals(extension)) {
               FileSystemStorage fs = FileSystemStorage.getInstance();
               try {
                   InputStream fis = fs.openInputStream(file);
                   hi.addComponent(new SpanLabel(Util.readToString(fis)));
               } catch (Exception ex) {
                   Log.e(ex);
               }
           } else {
               hi.add("Selected file "+file);
           }
        }
        hi.revalidate();
    });
}

Troubleshooting:

See Troubleshooting wiki page for common errors related to this library and how to fix them.

Other Useful Links

Credits

About

Filechooser for Codename One

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 53.8%
  • Java 43.5%
  • JavaScript 1.6%
  • C# 1.1%