這樣的代碼..如何從原始文件夾獲取文件到列表視圖?
public class SongsManager {
// SDCard Path
final String MEDIA_PATH = new String("/sdcard/");//this will I switch to raw folder..
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
// Constructor
public SongsManager(){
}
/**
* Function to read all mp3 files from sdcard
* and store the details in ArrayList
* */
public ArrayList<HashMap<String, String>> getPlayList(){
File home = new File(MEDIA_PATH);
if (home.listFiles(new FileExtensionFilter()).length > 0) {
for (File file : home.listFiles(new FileExtensionFilter())) {
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", file.getName().substring(0, (file.getName().length() - 4)));
song.put("songPath", file.getPath());
// Adding each song to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}
但是從原始文件讀取...
那隻能讀取原始文件中的一個文件,如何讀取原始文件夾中的所有文件? – 2013-03-06 14:41:25
@DewaYudie我編輯了我的答案,看看更新。 – Esparver 2013-03-06 14:42:58
我不明白在我的代碼中實現,你能幫我嗎? – 2013-03-06 16:04:21