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);
添加回答
舉報