我建立的音乐播放器应用程序从SD卡从服务器上下载,我收集数据和保存文件命名为ArrayList中获得指数<HashMap的<字符串,字符串>>
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
现在问题是我想根据用户点击回收站项目来播放mp3文件,因此,我需要为特定名称指定索引号。
如何获取索引用于传递mp3文件的名称?
/**
* 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());
Log.d(TAG, "getPlayList() called title = "+file.getName().substring(0, (file.getName().length() - 4))+" Path = "+file.getPath());
// Adding each song to SongList
songsList.add(song);
}
}
// return songs list array
return songsList;
}
我建议你做一个'Song'类而不是在HashMap中存储属性 –
是的,POJO是一个很好的选择,但是我已经实现了HashMap,所以现在需要一段时间来实现和更改所有的类。 –