实时监听adapter点击哪一个item项

【核心代码】

 @Override
    public void onBindViewHolder(AudioSortHolder holder, final int position) {
        if (clickPosition == position) {
            holder.tvSort.setTextColor(Color.parseColor("#ffffff"));
            holder.itemView.setBackground(mContext.getResources().getDrawable(R.drawable.shape_sort_green));
        } else {
            holder.tvSort.setTextColor(Color.parseColor("#9e9e9e"));
            holder.itemView.setBackground(mContext.getResources().getDrawable(R.drawable.shape_sort_white));
        }
        holder.tvSort.setText(mPlayTypeBeen.get(position).getName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onItemClick(position);
                }
                clickPosition = position;
                notifyDataSetChanged();
            }
        });
    }

【接口】

 public interface OnItemClickListener {
        void onItemClick(int position);
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

【调用】

  mVideoSortAdapter.setOnItemClickListener(new AudioSortAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                mPresenter.getChannelVideoList(mChannelId,"V","1","100",playTypeList.get(position).getId()+"");
                mSortRecyclerView.scrollToPosition(position);
            }
        });

你可能感兴趣的:(实时监听adapter点击哪一个item项)