hedzr / android-file-chooser

a lightweight file/folder chooser or picker
Apache License 2.0
284 stars 62 forks source link

select multiple #84

Open pateljigar7210 opened 4 years ago

pateljigar7210 commented 4 years ago

ArrayList paths = new ArrayList<>();

    new ChooserDialog(getActivity())
            .withStartFile(Environment.getExternalStorageDirectory().getAbsolutePath().toString())
            .enableMultiple(true)

            .withChosenListener(new ChooserDialog.Result() {
                @Override
                public void onChoosePath(String path, File pathFile) {
                    if("/storage/emulated/0".equals(path)){
                        LogClass.e("FILEs", "list : "+paths);
                    }else {
                        if(paths.contains(path)){
                            paths.remove(path);
                        }else {
                            paths.add(path);
                        } 
                    }
                }
            })
            // to handle the back key pressed or clicked outside the dialog:
            .withOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    LogClass.e("CANCEL", "CANCEL");
                    dialog.cancel(); // MUST have
                }
            })
            .withResources(R.string.title_choose_any_file, R.string.title_choose, R.string.dialog_cancel)
            .withStringResources("Title", "OK", "Cancel")
            .build()
            .show();