1 回答
TA贡献1806条经验 获得超8个赞
String resourceId = AppUtil.getResourceId(SearchSong.this, myList);
Song selectedSong = mySongCollection.searchById(resourceId);
resourceId 将成为列表视图元素的 id(例如,第一个元素 id = 0、第二个 id = 1 等等)。
public Song searchById (String id){
Song selectedSong = null;
for(int index=0; index<allSongs.length; index++){
selectedSong = allSongs[index];
if(selectedSong.getId().equals(id)){
return selectedSong;
}
}
return selectedSong;
}
应该:
public Song searchById (String id){
//we are returning the song selected by the index of its Arrays
Song selectedSong = allSongs[Integer.parseInt(id)];
return selectedSong;
}
为什么?:
您返回实际的 songid,但在
Song selectedSong = mySongCollection.searchById(resourceId); <-- resourceId is already the Id stored in the database and not the index of mySongCollection.
intent.putExtra("id", selectedSong.getId());
您已经在使用实际歌曲 ID。这没有意义,因为您已经可以识别出实际的歌曲。因此,要么应用这些更改,要么更改此行:
intent.putExtra("id", resourceId);
添加回答
举报