【发布时间】:2017-11-19 06:08:35
【问题描述】:
我正在创建一个最近播放过歌曲的音乐播放器播放列表。我正在存储歌曲的数组列表和正在共享首选项中播放的歌曲的索引。我正在做的是从共享首选项中检索数组列表和歌曲索引并将其保存在另一个数组列表中。但问题是 recyclerView 一次只显示一首歌曲。
例如,如果我播放歌曲 A,recyclerView 应该在第一个位置显示歌曲 A,然后如果我播放歌曲 B,recyclerView 应该在第一个位置显示歌曲 B,在第二个位置显示歌曲 A。但它只显示第一个位置。
RecentlyPLayedsongs.java:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(this);
View view6 = inflater.inflate(R.layout.activity_recently_played, null);
FrameLayout container6 = (FrameLayout) findViewById(R.id.container);
container6.addView(view6);
recyclerView_recently_played = findViewById(R.id.recyclerView_recently_played);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView_recently_played.setLayoutManager(linearLayoutManager);
StorageUtil storageUtil2 = new StorageUtil(getApplicationContext());
SongList=storageUtil2.loadAudio();
pos = storageUtil2.loadAudioIndex();
songInfoModel = SongList.get(pos);
RecentlyPlayedList.add(songInfoModel);
adapter1 = new Playlist_Recently_Added_Adapter(RecentlyPlayedList, getApplicationContext());
recyclerView_recently_played.setAdapter(adapter1);
}
【问题讨论】:
-
这意味着您在播放歌曲 b 时添加到数组的第二个位置?
-
我希望在播放歌曲 B 时将歌曲 A 添加到第二个位置,并将歌曲 B 添加到第一个位置,就像在普通音乐播放器中一样
标签: android arraylist android-recyclerview android-mediaplayer android-music-player