我有一个名为PracticeAdapter的类,它有一个覆盖方法public void onBindViewHolder(ViewHolder holder, int position)
,其中包含holder.itemView
。我想在名为PracticeSteps的另一个类中访问此holder.itemView
,并在其中设置其背景颜色。
我怎样才能做到这一点?这是我的代码:
PracticeSteps类:
public class PracticeSteps extends Fragment {
public void checkOrderOfProcedures(){
mItemArray = new ArrayList<>();
mDragListView.setDragListListener(new DragListView.DragListListenerAdapter() {
@Override
public void onItemDragEnded(final int fromPosition, final int toPosition) {
if (Long.valueOf(toPosition).equals((Long)(mItemArray.get(toPosition).first))) {
Toast.makeText(mDragListView.getContext(), "Correct position", Toast.LENGTH_SHORT).show();
//SET THE BACKGROUND COLOR OF holder.itemView in here
} else {
Toast.makeText(mDragListView.getContext(), "Incorrect position", Toast.LENGTH_SHORT).show();
}
}
});
setupListRecyclerView();
}
PracticeAdapter类:
public class PracticeItemAdapter extends DragItemAdapter<Pair<Long, String>, PracticeItemAdapter.ViewHolder> {
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
String text = mItemList.get(position).second;
holder.mText.setText(text);
holder.itemView.setTag(text);
//ACCESS THE holder.itemView from here
}