android - 如何从模拟器的sdcard中获取所有图片并显示在listView中?

标签 android

我的模拟器的 SD 卡中有一个名为 images 的文件夹。此文件夹包含从我的应用程序中单击的图片。我想将该文件夹中的所有图片显示到 ListView 中。我怎样才能做到这一点?提前致谢。

最佳答案

这应该可以让您开始使用它。

http://android-er.blogspot.com/2010/01/android-file-explorer-with-jpgs-exif_08.html

计算需求的简单逻辑,

 private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);

item = new ArrayList<String>();
path = new ArrayList<String>();

File f = new File(dirPath);
File[] files = f.listFiles();

if(!dirPath.equals(root))
{

 item.add(root);
 path.add(root);

 item.add("../");
 path.add(f.getParent());

}

for(int i=0; i < files.length; i++)
{
  File file = files[i];
  path.add(file.getPath());
  if(file.isDirectory())
   item.add(file.getName() + "/");
  else
   item.add(file.getName());
}

ArrayAdapter<String> fileList =
 new ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
 }

关于android - 如何从模拟器的sdcard中获取所有图片并显示在listView中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7303943/

相关文章:

php - android 应用程序与 web 服务通信的安全性

android - 尽管调用了 addToBackStack(null),但 Fragment BackStack 不起作用

android - Gradle:构建Android库后如何运行自定义任务?

java - 用于解析该字符串的正则表达式或java解决方案

java - 我应该如何构建我的项目以在 Android 客户端应用程序和 JSP 服务器应用程序之间共享类?

java - Firebase 云消息传递 - onMessageReceived 不工作

java - Android:使 TableRow 独立于 TableLayout

android - 以编程方式将带有 LayerDrawable 的 StateListDrawable 添加到 Button 的问题

android - Android 上的 FFmpeg 命令行

android - com.android.volley.NoConnectionError : javax.net.ssl.SSLHandshakeException : javax.net.ssl.SSLProtocolException:SSL 握手中止: