这里面临排序文件的问题。从资源文件夹中选择文件。如何按升序对文件进行排序? 这里是我的代码:如何对资产文件夹中的文件进行排序?
//fillGrid
private void fillGridAdapter(int cat) {
ASSETS_IMAGE_DIR = imagePath[cat];
addImages(getImages(imagePath[cat]));
}
//Adds the files
private void addImages(String[] temp){
imBitmap = new Bitmap[temp.length];
if(temp != null) {
for(int i = 0; i < temp.length; i++){
try {
imBitmap[i] = getBitmapFromAsset(imagePath[g.getImageCat()]+"/"+temp[i]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private String[] getImages(String f){
try {
AssetManager assetManager = getResources().getAssets();
String[] temp = assetManager.list(f);
Arrays.sort(temp);
return temp;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
后assetManager.list(F)的String []温度 - (1.JPG,10.JPG,12.JPG ... 9.jpg)。 After Arrays.sort(temp) - (1.jpg,10.jpg,12.jpg ... 9.jpg)。我需要 - 1.jpg,2.jpg,3.jpg ... n.jpg。
资产文件夹中的图片数是固定的吗? –
将所有图像名称添加到arraylist并使用集合进行排序 – Senthil