RecyclerView always calls the adapter with position within a data set bounds, so that when a data set is empty getItemViewType and onBindViewHolder won't be called.
According to the source code INameableAdapter could be called even if the list is empty, while the doc has nothing about this behaviour. Actually even the demo application is crashing if activity.getPackageManager().getInstalledApplications (AppData.java:AppData.processApps) returns an empty list, making testAdapter to try to reach a first element of empty list leading to OOB exception.
So I see two ways to solve this:
make it clear that INameableAdapter.getCharacterForElement could be called with invalid index
RecyclerView always calls the adapter with
position
within a data set bounds, so that when a data set is emptygetItemViewType
andonBindViewHolder
won't be called.According to the source code
INameableAdapter
could be called even if the list is empty, while the doc has nothing about this behaviour. Actually even the demo application is crashing ifactivity.getPackageManager().getInstalledApplications
(AppData.java:AppData.processApps) returns an empty list, makingtestAdapter
to try to reach a first element of empty list leading to OOB exception.So I see two ways to solve this:
INameableAdapter.getCharacterForElement
could be called with invalid index