7

I'm developing Android application that must show all images stored inside SD card. I did it successfully except I getting strange behavior when switching to landscape mode (in fact, I do not see anything in my grid).

In logcat I get this message : RecyclerView﹕ No adapter attached; skipping layout

Yes, I am using RecyclerView and this only happens in landscape, when I rotate back to portrait again, Fragment is retained and I can see every single bitmap inside my grid again.

Now, does anyone know why this is happening to me ? Here is how I set my adapter to recyclerView (inside a fragment):

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (cursor.moveToFirst()) {
        adapter = new ImageAdapter(getActivity(), cursor, imageManager);
        imagesGrid.setAdapter(adapter);
    }
}

Oh, and by the way, I am using default GridLayoutManager for RecyclerView.

emilancius
  • 296
  • 1
  • 5
  • 15
  • My guess is that onLoadFinished() is only being called once when your app starts. Set a breakpoint there and check if it runs when you switch from portrait to landscape. My guess is it does not and thus, adapter is null. – iheanyi Nov 10 '14 at 20:58
  • I recently read that this error occurs when adapter is null. But how should I set adapter in onCreateView when I need a cursor to set it up ? Is it only possible way to update RecyclerView.Adapter with CursorAdapter methods ? – emilancius Nov 10 '14 at 21:03
  • I'm not sure I understand why you're unable to get the cursor somewhere else, like in onResume? – iheanyi Nov 10 '14 at 21:14
  • Well, I'm using default CursorLoader and calling initLoeader() inside onCreateView(). How should I get returned cursor in onResume ? In the other hand, initLoader should be called every time when fragment is recreated (because this metod is inside onCreateView method). – emilancius Nov 10 '14 at 21:27
  • Can you help me out with this one http://stackoverflow.com/questions/30524798/some-data-not-set-by-recycler-adater – Sagar Devanga May 29 '15 at 08:46

0 Answers0