问题描述
在我的代码中,我试图收集列表中的所有视频文件,并将其扭曲到父目录中,并显示在recycler view
中,而在显示时,我却得到了一个文件夹名0
,我听不懂0
文件夹的来源。
0
文件夹列出了我的存储设备中的所有文件,这些文件在它们各自的文件夹中完美地变形了。
这是文件夹零的屏幕截图。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
foldersList = new ArrayList<>();
folderpath = new ArrayList<>();
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new linearlayoutmanager(this));
parseAllVideo();
getUniqueFolders();
adapter = new FolderAdapter(this,foldersList);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
private void parseAllVideo() {
try {
String[] proj = {
MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA};
Cursor videocursor = this.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj,null,null);
if (videocursor != null) {
if (videocursor.movetoFirst()) {
int path_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
do {
String filepath = videocursor.getString(path_index);
String folder_path = MyUtils.getParentDirPath(filepath);
File file = new File(filepath);
if (file.exists()) {
}
folderpath.add(folder_path);
} while (videocursor.movetoNext());
}
videocursor.close();
}
} catch (Exception e) {
e.printstacktrace();
}
}
private void getUniqueFolders() {
List<String> newList = new ArrayList<>(new HashSet<>(folderpath));
Collections.sort(newList);
for (int i = 0; i < newList.size(); i++) {
String folder_name = newList.get(i).substring(newList.get(i).lastIndexOf("/") + 1);
FolderModel folder = new FolderModel(folder_name,newList.get(i));
Log.d(TAG,"base file = " + folder);
foldersList.add(folder);
}
}![enter image description here](https://i.stack.imgur.com/rgQrz.jpg)
这里是要存档的内容,内部文件夹中的文件以缩略图的形式显示(滑动,位...),但是使用我的代码,0
文件夹包含了我存储中的所有文件,>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)