简体   繁体   中英

Android Studio: Displaying a list of pictures inside a folder?

Alright, I am trying to display 170+ jpg images on the screen. So far my issue is having the app find the images and add them to a list. (I put all the images in the mipmap-xxhdpi folder because that seemed to be the only place where ImageView could find them)

Here is my code:

    ArrayList img = new ArrayList<Image>();
    File folder = new File("@mipmap");
    File[] fille = folder.listFiles();
    for (int i = 0; i< fille.length; i++) {
        img.add(fille[i]);
  ListAdapter picAdapt = new ArrayAdapter<Image>(this, android.R.layout.simple_gallery_item, img); ListView picListView = (ListView) findViewById(R.id.gallery); picListView.setAdapter(picAdapt); 

I think the app is trying to find the picture in a directory on the android device instead inside the actual APK, but then again I have no idea. I am brand new to Java and Android Studio; the only prior knowledge I have is Python.

All help is appreciated, Thanks!

UPDATE: After googling for a while longer, I started to wonder whether if I could append an item from a File[] Array into an Image[] Array. Maybe the app found the pictures but couldn't append them to the list so the list stayed empty? How would I do this?

Use a URI URL to locate the directory of the picture instead. And then use an Integer array to store the image's id. And recall them as you need to via Id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM