Android access recyclerview项目未被回收

Android access recyclerview项目未被回收,android,Android,我试图突出显示recycleriveview中的一些项目,我成功地通过编程实现了这一点,但当我试图突出显示其中一些未被回收的项目时,我得到了空指针。有没有一种方法可以通过编程scrooling或其他方式回收我突出显示的项目 到目前为止,我所尝试的: layoutManager.scrollToPositionWithOffset(position that I'm highlighting, 2); 我做错的是,在我的onBindViewHolder上,我已经有了这样的东西,我太担心在

我试图突出显示
recycleriveview
中的一些项目,我成功地通过编程实现了这一点,但当我试图突出显示其中一些未被
回收的项目时,我得到了空指针。有没有一种方法可以通过编程scrooling或其他方式回收我突出显示的项目

到目前为止,我所尝试的:

    layoutManager.scrollToPositionWithOffset(position that I'm highlighting, 2);

我做错的是,在我的
onBindViewHolder
上,我已经有了这样的东西,我太担心在recyclerview中设置项目了:

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    holder.mTextView.setText(mDataset[position]);
    if(selectedItem == position){
        holder.itemView.setBackgroundColor(Color.argb(40, 100, 100, 230));
    }
    else {
        holder.itemView.setBackgroundColor(Color.argb(0, 0, 0, 0));
    }
} 
如果屏幕上没有标记为highlight If的项目,则在scrooling时将其高亮显示

当我试图高亮显示一个项目时,我会检查viewholder的位置是否为空,如果不是,我可以进行更改,如果为空,我会等待
recyclerView
高亮显示它

    mAdapter.setSelectedItem(myDataList.indexOf(name));
    if( musicList.findViewHolderForPosition(myDataList.indexOf(name)) != null ){
        musicList.findViewHolderForPosition(myDataList.indexOf(name)).itemView.setBackgroundColor(Color.argb(40, 100, 100, 230));
    }
    mAdapter.notifyDataSetChanged();