在Adapter中设置cardView的点击事件
需要定位用户点击的位置
问题:holder.getAdapterPosition()一直返回-1,而不是返回点击的位置

解决:使用tag解决

@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext==null){
            mContext=parent.getContext();
        }
        View view= LayoutInflater.from(mContext).inflate(R.layout.essay_item,parent,false);
//点击显示的资源后进入详细页面
        final ViewHolder holder = new ViewHolder(view);
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取当前点击
                //int position = holder.getAdapterPosition();
               // getState((Integer) v.getTag());
//取出position
                int position =  (Integer) v.getTag();
                /*if(position == -1)+1
                    return;*/
                EssayItem fruit = mEssayItem.get(position);
                Intent intent = new Intent(mContext, CurrentItemActivity.class);
                intent.putExtra(CurrentItemActivity.FRUIT_NAME, fruit.getEssayTitle());
                intent.putExtra(CurrentItemActivity.FRUIT_IMAGE_ID, fruit.getImageId());
                LogUtil.d(TAG,fruit.toString());
                mContext.startActivity(intent);
            }
        });
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ListAdapter.ViewHolder holder, int position) {
        EssayItem essay=mEssayItem.get(position);
        holder.essayName.setText(essay.getEssayTitle());
        Glide.with(mContext).load(essay.getImageId()).into(holder.essayImage);
//记录当前position
        holder.itemView.setTag(position);
    }