2013-03-26 41 views
0

我想創建內部存儲器庫文件夾像下面的截圖:機器人怎麼辦我克里特文件夾,並在屏幕上顯示

enter image description here

當點擊一張專輯,我希望它顯示其中的圖像列表。

String dirPath = getFilesDir().getAbsolutePath() + File.separator + "newfoldername"; 
File projDir = new File(dirPath); 
+0

我想這只是一個帶有四個'ImageViews'的LinearLayout',它根據捕獲圖像時的數據動態設置。它實際上不是文件夾的可視化表示。 – 2013-03-26 07:21:11

回答

0

爲您的應用程序創建一個文件夾,這裏是下面的代碼,負責你的文件夾,並檢查字符串名稱,如果SD卡是可用的,如果它是創建一個名稱的文件夾中的圖片文件夾否則,如果SD卡不存在,則創建與其中,app安裝像數據/ data.com.myapp /文件內部存儲器相同名稱的文件夾/ yourFolder

public File createDirectoryForApp(Context con, String dirName) 
{ 
File directory=null; 
    /* 
    * This sections checks the phone to see if there is a SD card. if 
    * there is an SD card, a directory is created on the SD card 
    */ 

    if (isExternalStorageWritable()) { 

     // search for directory on SD card 
     directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) 
       + "/"+dirName+"/"); 

     // if no directory exists, create new directory to store test 
     // results 
     if (!directory.exists()) { 
      directory.mkdir(); 
     } 

    } 
    else 
    { 
      //create new file directory object in internal memory as no SD card is available 
     directory = new File(con.getFilesDir() 
       + "/"+dirName+"/"); 

     // if no directory exists, create new directory 
     if (!directory.exists()) { 
      directory.mkdir(); 
     } 


    } 
    return directory; 
     } 

//method used above to check external storage 
public static boolean isExternalStorageWritable() { 
    String state = Environment.getExternalStorageState(); 
    if (Environment.MEDIA_MOUNTED.equals(state)) { 
     return true; 
    } 
    return false; 
} 

,並獲得與特定的擴展,並進一步在文件內的文件的目錄(這也是文件)你可以使用以下方法

private List<File> getListFiles(File parentDir) { 
ArrayList<File> inFiles = new ArrayList<File>(); 
File[] files = parentDir.listFiles(); 
for (File file : files) { 
    if (file.isDirectory()) { 
     inFiles.addAll(getListFiles(file)); 
    } else { 
     if(file.getName().endsWith(".png")){ 
      inFiles.add(file); 
     } 
    } 
} 
return inFiles; 
} 

並在視覺上代表所有這些依賴於您的信息,即如何設計佈局並在從這些文件中獲取數據後顯示數據。

+0

我使用此字符串在我的內存中創建文件夾dirPath = getFilesDir()。getAbsolutePath()+ File.separator +「picture」; File projDir = new File(dirPath); 我的文件夾名稱是「圖片」我如何顯示圖片文件夾ons creen?不是內容 – nazeer 2013-03-26 07:41:24

+0

據我所知沒有單行代碼,它可以讓你顯示你的目錄信息,就像你在上面提到的圖片..你可以使用第二種方法獲取目錄中的文件,然後將這些文件中的信息顯示到根據上圖設計的自定義佈局中 – 2013-03-26 11:05:43