I poulate my RecyclerView with 250 items. Each view only has 4 TextViews. When creating the adapter for the RecyclerView onCreateViewHolder takes about 5 ms and onBindViewHolder takes about 3 ms. For 250 items we then have a delay of 2 seconds. In this two seconds the UI freezes, since the adapter assignment has to be executed on the Main-Thread.
For example in the onCreateViewHolder there is not much going on beside a layout inflation:
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
long lTime = System.currentTimeMillis();
switch (viewType) {
case TYPE_HEADER:
SpendingHeader lResult = new SpendingHeader(LayoutInflater.from(mContext).inflate(R.layout.layout_spending_item_header, null));
LogUtils.logTime(lTime, TAG, "onCreateViewHolder");
return lResult;
default:
SpendingItem lResult2 = new SpendingItem(LayoutInflater.from(mContext).inflate(R.layout.layout_spending_item, null));
LogUtils.logTime(lTime, TAG, "onCreateViewHolder");
return lResult2;
}
}
The complete computation stuff is done on a background thread in an AsyncTask. Only onCerateViewHolder and onBindViewHolder take so much time such that the progress bar freezes. I'm fine to wait but its not good that the progressbar freezes. Is there a way to circumvent this? Also I dont want a lazy list where you get a progressbar for example after scroll to the 30th item.
Note: Also my Recyclerview must be part of a NestedScrollView for actionbarBar ControllableLayout behaviour. Might this be a problem? See here