【发布时间】:2019-10-17 06:02:00
【问题描述】:
我有一个 GridView 来显示来自 sdcard 的图像和他们的名字 但我想按名称从 A 到 Z 对图像进行排序 这是我的代码
if (file.isDirectory()) {
listFile = file.listFiles();
// Create a String array for FilePathStrings
FilePathStrings = new String[listFile.length];
// Create a String array for FileNameStrings
FileNameStrings = new String[listFile.length];
for (int i = 0; i < listFile.length; i++) {
// Get the path of the image file
FilePathStrings[i] = listFile[i].getAbsolutePath();
// Get the name image file
FileNameStrings[i] = listFile[i].getName();
}
}
// Locate the GridView in gridview_main.xml
grid = (GridView) findViewById(R.id.cgridview);
// Pass String arrays to LazyAdapter Class
adapter = new CGridViewAdapter(this, FilePathStrings, FileNameStrings);
// Set the LazyAdapter to the GridView
grid.setAdapter(adapter);
我如何对它们进行排序?
【问题讨论】:
-
我的代码中没有 arrylist
-
你可以使用
Arrays.sort(list);stackoverflow.com/a/23806797/9792247 -
但是我的适配器使用两个 String[] 而不是 arrylist
-
引用那个链接,列表只是变量的名称,它的类型是
String[]