Dushyant Suthar Dushyant Suthar - 1 month ago 17
Android Question

Why does Recycler View scroll back to last three items?

I want to show list of songs in the device by 'RecyclerView'. Each item in the list consists of some child items such as song name album art etc. When the recycler view is set to show just details like song name and 'NO ALBUM ART' it is working fine as scrolling is smooth and scrolls to last easily but when I am showing album art of each song in the list then the problem occurs. The problem is when I am scrolling the songs to the last item with one time long scroll (as list is very small so we can scroll to the last item with one scroll) the recycler view shows me scolling animation till the last item in the list when the scrolling animation stop the recycler view ends up showing last three list items as last and I have scroll one more time to get the last list items on the screen. I am using Picasso Library to show the album art and I am getting the album art 'Uri' by these lines of code :

Uri ART_CONTENT_URI = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(ART_CONTENT_URI,thisAlbumId);


I am setting the adapter to recycler view like this :

new Thread(new Runnable()
{
@Override
public void run()
{
MusicService.songList = new ArrayList<>();
getSongList();
runOnUiThread(new Runnable()
{
@Override
public void run()
{
recyclerView=(RecyclerView) findViewById(R.id.song_list_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerViewAdapter = new RecyclerViewAdapter(MainActivity.this);
recyclerView.setAdapter(recyclerViewAdapter);
recyclerView.setHasFixedSize(true);
}
});
}
}).start();


I hope you understood it well. Seeking for errors like things I am doing wrong or forgetting something.

Here is my error log :

07-24 23:55:43.698 6069-6069/com.sayings.developer.music E/ExtMediaPlayer-JNI: QCMediaPlayer could not be located....
07-24 23:55:43.698 6069-6069/com.sayings.developer.music E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
07-24 23:55:43.698 6069-6069/com.sayings.developer.music E/ExtMediaPlayer-JNI: QCMediaPlayer could not be located....
07-24 23:55:43.699 6069-6069/com.sayings.developer.music E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
07-25 00:02:04.123 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:05.273 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:05.415 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:05.488 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:06.242 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:07.087 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:23.624 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout
07-25 00:02:25.452 6069-6069/com.sayings.developer.music E/RecyclerView: No adapter attached; skipping layout

Answer

The problem was there was change in values of ArrayAdapter which was attached to the recycler view so I have changed the logic and got my error removed.