如何实现此代码的直接文件夹路径,这是一个带图像卷轴滑块的图像查看器项目任何人都知道解决方案请帮助我。 有人可以帮助我
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class Images {
private int currentImage = 0;
private List<String> paths = new ArrayList<>();
public int getImagesSize() {
return paths.size();
}
public String getImage(int index) {
Log.i("Image", paths.get(index));
return paths.get(index);
}
public void nextImageToDisplay() {
if (currentImage >= paths.size() - 1) {
currentImage = 0;
} else {
currentImage++;
}
}
public void addImage(String path) {
this.paths.add(path);
}
public String getCurrentImage() {
return paths.get(currentImage);
}
public void setPathsToImages(List<String> paths) {
this.paths = new ArrayList<>(paths);
}
public boolean contains(String imagePath) {
return this.paths.contains(imagePath);
}
}
答案 0 :(得分:0)
您可以轻松完成。假设您想从SD卡中的/ Pictures / Screenshots文件夹中获取所有文件。
File sdCardRoot = Environment.getExternalStorageDirectory();
File yourDir = new File(sdCardRoot, "/Pictures/Screenshots");
List<String> paths = new ArrayList<String>();
for (File f : yourDir.listFiles()) {
if (f.isFile()){
String name = f.getName();
System.out.println("name is :"+name);
paths.add(name);
}
}