简体   繁体   中英

Android developing: Getting the name of Images

Was searching for a bit here now but didnt find anything similar. So my problem is: I want to write a method that gets a filename and an ArrayList as a parameter with it and searchs through this Arraylist. When the filename equals the Name of the Image in this Arraylist, it should return this one. Started to do it like this now:

private Image getEfnSig(String efn, ArrayList<Image> efnSignatures){
    for(int i=0; i<efnSignatures.size(); i++){
        if(efn.equals(efnSignatures.get(i).getClass().getName())){
            return efnSignatures.get(i);
        }
    }
    return null;
}

My Problem here is, how do i get the name of an Image in this Arraylist. Because there are, like it seems, no Methods to just get the Name.

Thanks in advance!

According to this documentation, there is no way to find out the file name of the image object. An image object should not always a file stored in file system.

You should pass to this method an ArrayList of File objects (like ArrayList<File> files ) instead of Image.

Use File List to get image file path from name :

private String getImagePath(String name, ArrayList<File> files){
   for(int i=0; i<files.size(); i++){
       if(name.equals(files.get(i).getName())){
          return files.get(i).getAbsolutePath();
       }
   }
   return "";
}

Okay I think I solved my problem and it wasnt really realted to what I asked :D Was safing the Images before after giving a Signature in my App and just needed to get them in another order it was actually working. But thank you very much anyway Guys. Really love this Page and its Users for this great support here!

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