There are pictures in the folder, you need to pull them out and insert them into the listView, everything is fine when you hard-write the name of the picture, and if the file is renamed ... How to make it so that you can load them without knowing the file name? And is it possible?

    2 answers 2

    Sobsna, you just need to make a function that would just return a list of file names from the folder. Having received them, you can already access the obvious ways in your list. For example this way:

    private ArrayList<String> getImagesName() { ArrayList<String> fileNames = new ArrayList<>(); String path = Environment.getExternalStorageDirectory() + "/myPictures/"; File filePath = new File(path); File file[] = filePath.listFiles(); for (int i = 0; i < file.length; i++) { fileNames.add(file[i].getName()); } return fileNames; } 

    How to get a list of names - then drive it into your adapter, and load the picture, knowing the full path to it.

      Provided that the file extension does not change and can be known in advance as follows:

      1. Run over all files in the target folder.
      2. We find out the file extension
      3. Compare it with the list of valid
      4. If suitable - set the image.