我在做什么错,是我担心太多的时候就设置在recyclerview项目我onBindViewHolder
我已经有这样的事情:
@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));
}
}
如果标记为突出显示的项目不在屏幕上以在sc highlight上突出显示。
当我试图突出显示一个项目时,我检查视图的位置是否为空,如果不是,我可以进行更改,如果为空,我等待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();