简体   繁体   English

Android开发:获取图像名称

[英]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. 所以我的问题是:我想编写一个获取文件名和ArrayList作为参数的方法,并搜索该Arraylist。 When the filename equals the Name of the Image in this Arraylist, it should return this one. 当文件名等于此Arraylist中的Image的名称时,它应返回该名称。 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. 我的问题是,如何在此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. 您应该将File对象的ArrayList(例如ArrayList<File> files )而不是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. 好的,我认为我已经解决了我的问题,它并没有真正实现我的要求:D在给我的应用程序签名后,一直在安全地处理图像,而只是需要以另一种顺序来使它们有效。 But thank you very much anyway Guys. 但是无论如何,非常感谢你们。 Really love this Page and its Users for this great support here! 真的很喜欢此页面及其用户在这里的强大支持!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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