2017-05-30 72 views
0

我目前正在使用光標在我的Android應用程序中列出SD卡上的所有圖像。但是,我希望光標在創建圖像後對圖像進行排序,但目前情況並非如此。如何更改光標中的排序

有誰知道我該怎麼辦?

謝謝!

public ArrayList<String> getFilePaths() { 
    Uri uri; 
    ArrayList<String> listOfAllImages = new ArrayList<String>(); 
    Cursor cursor; 
    int column_index_data, column_index_folder_name; 
    String PathOfImage = null; 
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 

    String[] projection = { MediaStore.MediaColumns.DATA, 
      MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; 

    cursor = Touch.getTouchContext().getContentResolver().query(uri, projection, null, 
      null, null); 

    column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); 
    column_index_folder_name = cursor 
      .getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); 


    ArrayList<String> filePaths = new ArrayList<String>(); 

    while (cursor.moveToNext()) { 
     PathOfImage = cursor.getString(column_index_data); 

     //listOfAllImages.add(PathOfImage); 


     filePaths.add(PathOfImage); 

    } 

回答

0
  1. 加選擇查詢:

    cursor = Touch.getTouchContext().getContentResolver().query(uri, projection, null, null, MediaStore.Images.Media.DATE_ADDED); 
    
  2. 改變了光標將文件添加:

    for (cursor.moveToLast(); !cursor.isBeforeFirst(); cursor.moveToPrevious()) { 
        PathOfImage = cursor.getString(column_index_data); 
    
        filePaths.add(PathOfImage); 
    }