0

There is a case where getItemCount within the RecycerView Adapter is not called for Android 4.0.3 (IceCreamSandwich). All other API versions don't have any problems. I create my adapter as follows:

Log.i(LOG_TAG, "array size = " + myArray.size());
adapter = new MyListAdapter(context, myArray, this);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

I inserted the Log.i to confirm there is an element in the array, which there is. Within the RecyclerView Adapter's constructor, I have:

public MyListAdapter(Context context, List<dataModel> data, MyListener listener) {
    this.context = context;
    this.mData = data;
    this.mInflater = LayoutInflater.from(context);
    this.mListener = listener;

    Log.i(LOG_TAG, "data size = " + this.mData.size());
}

And the data size is not empty within the constructor. What could be causing the getItemCount to not be called when the adapter is created and set to a RecyclerView? Again this only is happening with the IceCreamSandwich API, all others work perfectly.

Mike Walker
  • 2,944
  • 8
  • 30
  • 62
  • How do you know that `getItemCount` is not being called and why do you require it? – Ishita Sinha Aug 15 '16 at 18:45
  • I put logging within `getItemCount` and even `onCreateViewHolder` and neither get called. `getItemCount` tells the adapter how many data items there are, and of course `onCreateViewHolder` creates the views for the adapter. – Mike Walker Aug 15 '16 at 18:53
  • Beats me... Can you try with a couple other ICS devices and see if this behavior is reproduced? – Ishita Sinha Aug 15 '16 at 18:58
  • It was reported by a user of the app running `IceCreamSandwich`, and I had to use emulators for that version of Android. That's the only version which has this behavior. – Mike Walker Aug 15 '16 at 19:05

0 Answers0