CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.29k stars 5.15k forks source link

你好这个是我的多布局适配器代码和activity代码,我添加每个item的子view点击事件无效,这个怎么解决呢 #2682

Closed kris-liutao closed 5 years ago

kris-liutao commented 5 years ago

package com.reada.readahd.adapter;

import android.content.Context; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout;

import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.request.RequestOptions; import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.reada.readahd.R; import com.reada.readahd.entry.HomeAttentionUserListBean;

import java.util.List;

import static com.reada.readahd.app.ImApplication.getContext;

public class HomeAttentionDynListAdapter extends BaseMultiItemQuickAdapter<HomeAttentionUserListBean, BaseViewHolder> { private final Context context;

public HomeAttentionDynListAdapter(Context context, List<HomeAttentionUserListBean> data) {
    super(data);
    this.context = context;
    addItemType(HomeAttentionUserListBean.TYPE_SHUFA, R.layout.staggered_grid_item_shufa);//书画
    addItemType(HomeAttentionUserListBean.TYPE_HUIHUA, R.layout.staggered_grid_item_huihua);//绘画
    addItemType(HomeAttentionUserListBean.TYPE_ARTICLE, R.layout.staggered_grid_item_article);//文章
    addItemType(HomeAttentionUserListBean.TYPE_BOOKS, R.layout.staggered_grid_item_books);//书籍
    addItemType(HomeAttentionUserListBean.TYPE_VIDEOS, R.layout.staggered_grid_item_videos);//视频
}

@Override
protected void convert(BaseViewHolder helper, HomeAttentionUserListBean item) {
    switch (helper.getItemViewType()) {

        case HomeAttentionUserListBean.TYPE_SHUFA:
            ImageView iv_photo_shufa = helper.getView(R.id.iv_photo_shufa);//首页作品图片
            ImageView iv_head_shufa = helper.getView(R.id.iv_head_shufa);//首页作者头像
            ImageView iv_original = helper.getView(R.id.iv_original_shufa);//原创

            helper.setText(R.id.tv_userName_shufa, item.getAuthorname());
            helper.setText(R.id.tv_item_title_shufa, item.getName());//作品名
            helper.setText(R.id.tv_like_num_shufa, item.getTunum() + "");//喜欢数

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_shufa);

            helper.addOnClickListener(R.id.iv_head_shufa);
            helper.addOnClickListener(R.id.tv_like_num_shufa);
            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画类型
            ImageView iv_head_huihua = helper.getView(R.id.iv_head_huihua);//首页作者头像
            ImageView iv_original_huihua = helper.getView(R.id.iv_original_huihua);//原创
            ImageView iv_photo_huihua = helper.getView(R.id.iv_photo_huihua);//首页作品图片

            helper.setText(R.id.tv_userName_huihua, item.getAuthorname());
            helper.setText(R.id.tv_item_title_huihua, item.getProductName());//作品名
            helper.setText(R.id.tv_like_num_huihua, item.getTunum() + "");//喜欢数
            String type_huihua = item.getTypename();
            if ("1".equals(type_huihua)) {
                iv_original_huihua.setVisibility(View.VISIBLE);
            } else {
                iv_original_huihua.setVisibility(View.GONE);
            }

            //用glide加载网络图片 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getScale())
                    .apply(new RequestOptions()
                            .override(width1, screenWidth1)
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_photo_huihua);

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_huihua);
            helper.addOnClickListener(R.id.iv_head_huihua);
            helper.addOnClickListener(R.id.tv_like_num_huihua);
            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章类型
            ImageView iv_original_artical = helper.getView(R.id.iv_original_artical);//原创
            ImageView iv_head_artical = helper.getView(R.id.iv_head_artical);//原创

            String authorname = item.getAuthorname();
            if ("".equals(authorname)) {
                helper.setText(R.id.tv_userName_artical, "未知作者");
            } else {
                helper.setText(R.id.tv_userName_artical, authorname);
            }

            helper.setText(R.id.tv_item_title_artical, item.getName());//作品名
            helper.setText(R.id.tv_like_num_artical, item.getTunum() + "");//喜欢数

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_artical);
            helper.addOnClickListener(R.id.iv_head_artical);
            helper.addOnClickListener(R.id.tv_like_num_artical);
            break;

        case HomeAttentionUserListBean.TYPE_BOOKS://书籍类型
            ImageView iv_original_books = helper.getView(R.id.iv_original_books);//原创
            ImageView iv_head_books = helper.getView(R.id.iv_head_books);//原创

            helper.setText(R.id.tv_userName_books, item.getAuthorname());
            helper.setText(R.id.tv_item_title_books, item.getName());//作品名
            helper.setText(R.id.tv_like_num_books, item.getTunum() + "");//喜欢数
            String typename_books = item.getTypename();

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_books);
            helper.addOnClickListener(R.id.iv_head_books);
            helper.addOnClickListener(R.id.tv_like_num_books);
            break;
        case HomeAttentionUserListBean.TYPE_VIDEOS://视频类型

            ImageView iv_original_video = helper.getView(R.id.iv_original_video);//原创
            ImageView iv_head_video = helper.getView(R.id.iv_head_video);//原创
            ImageView iv_photo_video = helper.getView(R.id.iv_photo_video);//封面

            helper.setText(R.id.tv_userName_video, item.getAuthorname());
            helper.setText(R.id.tv_item_title_video, item.getProductName());//作品名
            helper.setText(R.id.tv_like_num_video, item.getTunum() + "");//喜欢数
            helper.setText(R.id.tv_like_name_video, item.getUserName());

            Glide.with(context)
                    .asBitmap()
                    .load(item.getScale())
                    .apply(new RequestOptions()
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_photo_video);
            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_video);
            helper.addOnClickListener(R.id.iv_head_video);
            helper.addOnClickListener(R.id.tv_like_num_video);
            break;

    }

}

}

activity代码onItemChildClick方法下面的子view点击事件无效

package com.reada.readahd.ui.fragment.home;

import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.util.Log; import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.reada.readahd.R; import com.reada.readahd.adapter.HomeAttentionDynListAdapter; import com.reada.readahd.base.BaseLazyFragment; import com.reada.readahd.entry.HomeAttentionUserListBean; import com.reada.readahd.mvp.contract.HomeAttentionUserListContract; import com.reada.readahd.mvp.persenter.HomeAttentionUserListPresenter; import com.reada.readahd.ui.activity.HomeImageDetailActivity; import com.reada.readahd.ui.activity.HomeVideoDetailActivity; import com.reada.readahd.utils.SPUtil; import com.reada.readahd.utils.StoreItemDecoration; import com.reada.readahd.utils.ToastUtils; import com.reada.readahd.views.LoadingLayout; import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList; import java.util.HashMap; import java.util.List;

import butterknife.BindView; import okhttp3.MediaType; import okhttp3.RequestBody;

public class HomeAttentionFragment extends BaseLazyFragment implements HomeAttentionUserListContract.View, OnRefreshLoadMoreListener, BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener, LoadingLayout.OnReloadListener, LoadingLayout.OnEmptyListener { private final String TAG = "HomeAttentionFragment"; @BindView(R.id.layout_loading) LoadingLayout layoutLoading;

@BindView(R.id.rv_home_attention)
RecyclerView rvHomeAttention;
@BindView(R.id.layout_refresh)
SmartRefreshLayout layoutRefresh;

private HomeAttentionDynListAdapter mAdapter;
private ArrayList<HomeAttentionUserListBean> mAttentionList1 = new ArrayList<>();
private ArrayList<HomeAttentionUserListBean> mAttentionList2 = new ArrayList<>();
private List<Integer> mHeight;
private int currentPage = 1;
private String pageSize = "10";
private int userId;
private String sdate;

public HomeAttentionFragment() {
    // Required empty public constructor
}

@Override
protected int getContentViewId() {
    return R.layout.fragment_home_attention;
}

@Override
protected void initView() {
    layoutLoading.setStatus(LoadingLayout.LOADING);

    //多item瀑布流
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL);
    mAdapter = new HomeAttentionDynListAdapter(getActivity(), mAttentionList1);
    rvHomeAttention.setLayoutManager(layoutManager);
    //设置分割线
    rvHomeAttention.addItemDecoration(new StoreItemDecoration(30, 30));
    rvHomeAttention.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(this);

}

@Override
protected void initData() {
    userId = SPUtil.getInstance().getInt("id");

// sdate = DateUtil.longToString(System.currentTimeMillis(), "yyyy-MM-dd"); sdate = SPUtil.getInstance().getString("loginTime"); getDate(currentPage, pageSize, userId, sdate);

}

private void getDate(int currentPage, String pageSize, int userId, String sdate) {
    Gson gson = new Gson();
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("currentPage", String.valueOf(currentPage));
    hashMap.put("pageSize", pageSize);
    hashMap.put("userId", String.valueOf(userId));
    hashMap.put("sdate", sdate);
    String strEntity = gson.toJson(hashMap);
    RequestBody requestBody =
            RequestBody.create(MediaType.parse("application/json; charset=utf-8"), strEntity);
    mPresenter.getAttentionUserList(requestBody);

}

private void getMoreDate(int currentPage, String pageSize, int userId, String sdate) {
    Gson gson = new Gson();
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("currentPage", String.valueOf(currentPage));
    hashMap.put("pageSize", pageSize);
    hashMap.put("userId", String.valueOf(userId));
    hashMap.put("sdate", sdate);
    String strEntity = gson.toJson(hashMap);
    RequestBody requestBody =
            RequestBody.create(MediaType.parse("application/json; charset=utf-8"), strEntity);
    mPresenter.loadMoreAttentionUserList(requestBody);

}

@Override
protected void initListener() {
    layoutRefresh.setOnRefreshLoadMoreListener(this);
    layoutLoading.setOnReloadListener(this);
    layoutLoading.setOnEmptyListener(this);

}

@Override
protected HomeAttentionUserListPresenter getPresenter() {
    return new HomeAttentionUserListPresenter(this);
}

@Override
public void getOnSuccessAttentionUserList(String userdynlist) {
    Log.i(TAG, "首页动态关注列表: " + userdynlist);

    if (userdynlist.length() <= 2) {
        layoutLoading.setStatus(LoadingLayout.EMPTY);
    } else {
        layoutLoading.setStatus(LoadingLayout.SUCCESS);

        layoutRefresh.finishRefresh(true);
        layoutRefresh.setNoMoreData(false);
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonArray Jarray = parser.parse(userdynlist).getAsJsonArray();

        int previousSize = mAttentionList1.size();
        mAttentionList1.clear();
        mAdapter.notifyItemRangeRemoved(0, previousSize);

        for (JsonElement obj : Jarray) {
            HomeAttentionUserListBean homeAttentionUserListBean = gson.fromJson(obj, HomeAttentionUserListBean.class);

            mAttentionList1.add(homeAttentionUserListBean);
        }
        mAdapter.notifyItemRangeInserted(0, mAttentionList1.size());

    }

}

@Override
public void loadMoreSuccess(String userdynlist) {
    mAttentionList2.clear();

    layoutLoading.setStatus(LoadingLayout.SUCCESS);
    layoutRefresh.finishLoadMore(true);
    Gson gson = new Gson();
    JsonParser parser = new JsonParser();
    JsonArray Jarray = parser.parse(userdynlist).getAsJsonArray();

    for (JsonElement obj : Jarray) {
        HomeAttentionUserListBean homeAttentionUserListBean = gson.fromJson(obj, HomeAttentionUserListBean.class);

        mAttentionList2.add(homeAttentionUserListBean);
    }
    mAdapter.addData(mAttentionList2);

}

@Override
public void loadMoreFail() {
    layoutRefresh.finishLoadMore(false);
}

@Override
public void onError() {
    layoutRefresh.finishLoadMore(false);
    layoutLoading.setStatus(LoadingLayout.ERROR);
}

@Override
public void noNetwork() {
    layoutRefresh.finishLoadMore(false);
    layoutLoading.setStatus(LoadingLayout.NO_NETWORK);
}

@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
    currentPage++;
    getMoreDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
    currentPage = 1;
    getDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    HomeAttentionUserListBean homeBean = mAdapter.getData().get(position);
    Intent intent = new Intent();
    switch (mAdapter.getItemViewType(position)) {
        case HomeAttentionUserListBean.TYPE_SHUFA://书法

            //方法2 带动画的跳转
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName = "transition_image";
            int authorid = homeBean.getAuthorid();
            int versionId = homeBean.getVersionId();
            ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle = compat.toBundle();
            if (bundle != null) {
                bundle.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle.putString("authorPic", homeBean.getAuthorpic());
                bundle.putString("userName", homeBean.getUserName());
                bundle.putString("authorid", String.valueOf(authorid));
                bundle.putString("worksName", homeBean.getProductName());//作品名
                bundle.putString("des", homeBean.getDes());//描述
                bundle.putString("versionId", String.valueOf(versionId));
                bundle.putString("productId", String.valueOf(homeBean.getId()));
                bundle.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle);
            ActivityCompat.startActivity(getContext(), intent, bundle);

            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画

            //方法2 带动画的跳转
            int[] location1 = new int[2];
            view.getLocationOnScreen(location1);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName1 = "transition_image";
            int authorid1 = homeBean.getAuthorid();
            int versionId1 = homeBean.getVersionId();
            ActivityOptionsCompat compat1 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName1);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle1 = compat1.toBundle();
            if (bundle1 != null) {
                bundle1.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle1.putString("authorPic", homeBean.getAuthorpic());
                bundle1.putString("userName", homeBean.getUserName());
                bundle1.putString("authorid", String.valueOf(authorid1));
                bundle1.putString("worksName", homeBean.getProductName());//作品名
                bundle1.putString("des", homeBean.getDes());//描述
                bundle1.putString("versionId", String.valueOf(versionId1));
                bundle1.putString("productId", String.valueOf(homeBean.getId()));
                bundle1.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle1);
            ActivityCompat.startActivity(getContext(), intent, bundle1);

            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章

            //方法2 带动画的跳转
            int[] location2 = new int[2];
            view.getLocationOnScreen(location2);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName2 = "transition_image";
            int authorid2 = homeBean.getAuthorid();
            int versionId2 = homeBean.getVersionId();
            ActivityOptionsCompat compat2 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName2);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle2 = compat2.toBundle();
            if (bundle2 != null) {
                bundle2.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle2.putString("authorPic", homeBean.getAuthorpic());
                bundle2.putString("userName", homeBean.getUserName());
                bundle2.putString("authorid", String.valueOf(authorid2));
                bundle2.putString("worksName", homeBean.getName());//作品名
                bundle2.putString("des", homeBean.getDes());//描述
                bundle2.putString("versionId", String.valueOf(versionId2));
                bundle2.putString("productId", String.valueOf(homeBean.getId()));
                bundle2.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle2);
            ActivityCompat.startActivity(getContext(), intent, bundle2);

            break;
        case HomeAttentionUserListBean.TYPE_BOOKS://书籍
            //方法2 带动画的跳转
            int[] location3 = new int[2];
            view.getLocationOnScreen(location3);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName3 = "transition_image";
            int authorid3 = homeBean.getAuthorid();
            int versionId3 = homeBean.getVersionId();
            ActivityOptionsCompat compat3 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName3);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle3 = compat3.toBundle();
            if (bundle3 != null) {
                bundle3.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle3.putString("authorPic", homeBean.getAuthorpic());
                bundle3.putString("userName", homeBean.getUserName());
                bundle3.putString("authorid", String.valueOf(authorid3));
                bundle3.putString("worksName", homeBean.getName());//作品名
                bundle3.putString("des", homeBean.getDes());//描述
                bundle3.putString("versionId", String.valueOf(versionId3));
                bundle3.putString("productId", String.valueOf(homeBean.getId()));
                bundle3.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle3);
            ActivityCompat.startActivity(getContext(), intent, bundle3);

            break;

        case HomeAttentionUserListBean.TYPE_VIDEOS://视频

            String productId_videos = String.valueOf(homeBean.getId());
            String authorId = String.valueOf(homeBean.getAuthorid());
            String scale = homeBean.getScale();
            String versionid = String.valueOf(homeBean.getVersionId());
            intent.setClass(getActivity(), HomeVideoDetailActivity.class);
            intent.putExtra("productId", productId_videos);
            intent.putExtra("authorid", authorId);
            intent.putExtra("scale", scale);
            intent.putExtra("productName", homeBean.getProductName());
            intent.putExtra("versionId", versionid);
            startActivity(intent);
            break;
    }
}

@Override
public void onReload() {
    getDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onEmpty() {
    layoutLoading.setStatus(LoadingLayout.EMPTY);
}

@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
    HomeAttentionUserListBean homeBean = mAdapter.getData().get(position);
    Intent intent = new Intent();
    switch (mAdapter.getItemViewType(position)) {

        case HomeAttentionUserListBean.TYPE_SHUFA://书法

            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  书法");
                }
            });
            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  会话");
                }
            });
            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  文章");
                }
            });
            break;
        case HomeAttentionUserListBean.TYPE_BOOKS://书籍
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  书籍");
                }
            });

            break;

        case HomeAttentionUserListBean.TYPE_VIDEOS://视频
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  视频");
                }
            });
            ToastUtils.showToast("类型  视频");

            break;
    }
}

}

Panxiaoan1993 commented 5 years ago

package com.reada.readahd.adapter;

import android.content.Context; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout;

import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.request.RequestOptions; import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.reada.readahd.R; import com.reada.readahd.entry.HomeAttentionUserListBean;

import java.util.List;

import static com.reada.readahd.app.ImApplication.getContext;

public class HomeAttentionDynListAdapter extends BaseMultiItemQuickAdapter<HomeAttentionUserListBean, BaseViewHolder> { private final Context context;

public HomeAttentionDynListAdapter(Context context, List<HomeAttentionUserListBean> data) {
    super(data);
    this.context = context;
    addItemType(HomeAttentionUserListBean.TYPE_SHUFA, R.layout.staggered_grid_item_shufa);//书画
    addItemType(HomeAttentionUserListBean.TYPE_HUIHUA, R.layout.staggered_grid_item_huihua);//绘画
    addItemType(HomeAttentionUserListBean.TYPE_ARTICLE, R.layout.staggered_grid_item_article);//文章
    addItemType(HomeAttentionUserListBean.TYPE_BOOKS, R.layout.staggered_grid_item_books);//书籍
    addItemType(HomeAttentionUserListBean.TYPE_VIDEOS, R.layout.staggered_grid_item_videos);//视频
}

@Override
protected void convert(BaseViewHolder helper, HomeAttentionUserListBean item) {
    switch (helper.getItemViewType()) {

        case HomeAttentionUserListBean.TYPE_SHUFA:
            ImageView iv_photo_shufa = helper.getView(R.id.iv_photo_shufa);//首页作品图片
            ImageView iv_head_shufa = helper.getView(R.id.iv_head_shufa);//首页作者头像
            ImageView iv_original = helper.getView(R.id.iv_original_shufa);//原创

            helper.setText(R.id.tv_userName_shufa, item.getAuthorname());
            helper.setText(R.id.tv_item_title_shufa, item.getName());//作品名
            helper.setText(R.id.tv_like_num_shufa, item.getTunum() + "");//喜欢数

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_shufa);

            helper.addOnClickListener(R.id.iv_head_shufa);
            helper.addOnClickListener(R.id.tv_like_num_shufa);
            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画类型
            ImageView iv_head_huihua = helper.getView(R.id.iv_head_huihua);//首页作者头像
            ImageView iv_original_huihua = helper.getView(R.id.iv_original_huihua);//原创
            ImageView iv_photo_huihua = helper.getView(R.id.iv_photo_huihua);//首页作品图片

            helper.setText(R.id.tv_userName_huihua, item.getAuthorname());
            helper.setText(R.id.tv_item_title_huihua, item.getProductName());//作品名
            helper.setText(R.id.tv_like_num_huihua, item.getTunum() + "");//喜欢数
            String type_huihua = item.getTypename();
            if ("1".equals(type_huihua)) {
                iv_original_huihua.setVisibility(View.VISIBLE);
            } else {
                iv_original_huihua.setVisibility(View.GONE);
            }

            //用glide加载网络图片 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getScale())
                    .apply(new RequestOptions()
                            .override(width1, screenWidth1)
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_photo_huihua);

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_huihua);
            helper.addOnClickListener(R.id.iv_head_huihua);
            helper.addOnClickListener(R.id.tv_like_num_huihua);
            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章类型
            ImageView iv_original_artical = helper.getView(R.id.iv_original_artical);//原创
            ImageView iv_head_artical = helper.getView(R.id.iv_head_artical);//原创

            String authorname = item.getAuthorname();
            if ("".equals(authorname)) {
                helper.setText(R.id.tv_userName_artical, "未知作者");
            } else {
                helper.setText(R.id.tv_userName_artical, authorname);
            }

            helper.setText(R.id.tv_item_title_artical, item.getName());//作品名
            helper.setText(R.id.tv_like_num_artical, item.getTunum() + "");//喜欢数

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_artical);
            helper.addOnClickListener(R.id.iv_head_artical);
            helper.addOnClickListener(R.id.tv_like_num_artical);
            break;

        case HomeAttentionUserListBean.TYPE_BOOKS://书籍类型
            ImageView iv_original_books = helper.getView(R.id.iv_original_books);//原创
            ImageView iv_head_books = helper.getView(R.id.iv_head_books);//原创

            helper.setText(R.id.tv_userName_books, item.getAuthorname());
            helper.setText(R.id.tv_item_title_books, item.getName());//作品名
            helper.setText(R.id.tv_like_num_books, item.getTunum() + "");//喜欢数
            String typename_books = item.getTypename();

            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_books);
            helper.addOnClickListener(R.id.iv_head_books);
            helper.addOnClickListener(R.id.tv_like_num_books);
            break;
        case HomeAttentionUserListBean.TYPE_VIDEOS://视频类型

            ImageView iv_original_video = helper.getView(R.id.iv_original_video);//原创
            ImageView iv_head_video = helper.getView(R.id.iv_head_video);//原创
            ImageView iv_photo_video = helper.getView(R.id.iv_photo_video);//封面

            helper.setText(R.id.tv_userName_video, item.getAuthorname());
            helper.setText(R.id.tv_item_title_video, item.getProductName());//作品名
            helper.setText(R.id.tv_like_num_video, item.getTunum() + "");//喜欢数
            helper.setText(R.id.tv_like_name_video, item.getUserName());

            Glide.with(context)
                    .asBitmap()
                    .load(item.getScale())
                    .apply(new RequestOptions()
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_photo_video);
            //用glide加载作者头像 并放入imageview中
            Glide.with(context)
                    .asBitmap()
                    .load(item.getAuthorpic())
                    .apply(new RequestOptions()
                            .error(R.mipmap.home_head_default)//图片加载失败后,显示的图片
                            .fallback(R.mipmap.home_head_default) //url为空的时候,显示的图片
                            .centerCrop()
                            .skipMemoryCache(true)
                            .diskCacheStrategy(DiskCacheStrategy.DATA))
                    .into(iv_head_video);
            helper.addOnClickListener(R.id.iv_head_video);
            helper.addOnClickListener(R.id.tv_like_num_video);
            break;

    }

}

}

activity代码onItemChildClick方法下面的子view点击事件无效

package com.reada.readahd.ui.fragment.home;

import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityOptionsCompat; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import android.util.Log; import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.reada.readahd.R; import com.reada.readahd.adapter.HomeAttentionDynListAdapter; import com.reada.readahd.base.BaseLazyFragment; import com.reada.readahd.entry.HomeAttentionUserListBean; import com.reada.readahd.mvp.contract.HomeAttentionUserListContract; import com.reada.readahd.mvp.persenter.HomeAttentionUserListPresenter; import com.reada.readahd.ui.activity.HomeImageDetailActivity; import com.reada.readahd.ui.activity.HomeVideoDetailActivity; import com.reada.readahd.utils.SPUtil; import com.reada.readahd.utils.StoreItemDecoration; import com.reada.readahd.utils.ToastUtils; import com.reada.readahd.views.LoadingLayout; import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList; import java.util.HashMap; import java.util.List;

import butterknife.BindView; import okhttp3.MediaType; import okhttp3.RequestBody;

public class HomeAttentionFragment extends BaseLazyFragment implements HomeAttentionUserListContract.View, OnRefreshLoadMoreListener, BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener, LoadingLayout.OnReloadListener, LoadingLayout.OnEmptyListener { private final String TAG = "HomeAttentionFragment"; @BindView(R.id.layout_loading) LoadingLayout layoutLoading;

@BindView(R.id.rv_home_attention)
RecyclerView rvHomeAttention;
@BindView(R.id.layout_refresh)
SmartRefreshLayout layoutRefresh;

private HomeAttentionDynListAdapter mAdapter;
private ArrayList<HomeAttentionUserListBean> mAttentionList1 = new ArrayList<>();
private ArrayList<HomeAttentionUserListBean> mAttentionList2 = new ArrayList<>();
private List<Integer> mHeight;
private int currentPage = 1;
private String pageSize = "10";
private int userId;
private String sdate;

public HomeAttentionFragment() {
    // Required empty public constructor
}

@Override
protected int getContentViewId() {
    return R.layout.fragment_home_attention;
}

@Override
protected void initView() {
    layoutLoading.setStatus(LoadingLayout.LOADING);

    //多item瀑布流
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL);
    mAdapter = new HomeAttentionDynListAdapter(getActivity(), mAttentionList1);
    rvHomeAttention.setLayoutManager(layoutManager);
    //设置分割线
    rvHomeAttention.addItemDecoration(new StoreItemDecoration(30, 30));
    rvHomeAttention.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(this);

}

@Override
protected void initData() {
    userId = SPUtil.getInstance().getInt("id");

// sdate = DateUtil.longToString(System.currentTimeMillis(), "yyyy-MM-dd"); sdate = SPUtil.getInstance().getString("loginTime"); getDate(currentPage, pageSize, userId, sdate);

}

private void getDate(int currentPage, String pageSize, int userId, String sdate) {
    Gson gson = new Gson();
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("currentPage", String.valueOf(currentPage));
    hashMap.put("pageSize", pageSize);
    hashMap.put("userId", String.valueOf(userId));
    hashMap.put("sdate", sdate);
    String strEntity = gson.toJson(hashMap);
    RequestBody requestBody =
            RequestBody.create(MediaType.parse("application/json; charset=utf-8"), strEntity);
    mPresenter.getAttentionUserList(requestBody);

}

private void getMoreDate(int currentPage, String pageSize, int userId, String sdate) {
    Gson gson = new Gson();
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("currentPage", String.valueOf(currentPage));
    hashMap.put("pageSize", pageSize);
    hashMap.put("userId", String.valueOf(userId));
    hashMap.put("sdate", sdate);
    String strEntity = gson.toJson(hashMap);
    RequestBody requestBody =
            RequestBody.create(MediaType.parse("application/json; charset=utf-8"), strEntity);
    mPresenter.loadMoreAttentionUserList(requestBody);

}

@Override
protected void initListener() {
    layoutRefresh.setOnRefreshLoadMoreListener(this);
    layoutLoading.setOnReloadListener(this);
    layoutLoading.setOnEmptyListener(this);

}

@Override
protected HomeAttentionUserListPresenter getPresenter() {
    return new HomeAttentionUserListPresenter(this);
}

@Override
public void getOnSuccessAttentionUserList(String userdynlist) {
    Log.i(TAG, "首页动态关注列表: " + userdynlist);

    if (userdynlist.length() <= 2) {
        layoutLoading.setStatus(LoadingLayout.EMPTY);
    } else {
        layoutLoading.setStatus(LoadingLayout.SUCCESS);

        layoutRefresh.finishRefresh(true);
        layoutRefresh.setNoMoreData(false);
        Gson gson = new Gson();
        JsonParser parser = new JsonParser();
        JsonArray Jarray = parser.parse(userdynlist).getAsJsonArray();

        int previousSize = mAttentionList1.size();
        mAttentionList1.clear();
        mAdapter.notifyItemRangeRemoved(0, previousSize);

        for (JsonElement obj : Jarray) {
            HomeAttentionUserListBean homeAttentionUserListBean = gson.fromJson(obj, HomeAttentionUserListBean.class);

            mAttentionList1.add(homeAttentionUserListBean);
        }
        mAdapter.notifyItemRangeInserted(0, mAttentionList1.size());

    }

}

@Override
public void loadMoreSuccess(String userdynlist) {
    mAttentionList2.clear();

    layoutLoading.setStatus(LoadingLayout.SUCCESS);
    layoutRefresh.finishLoadMore(true);
    Gson gson = new Gson();
    JsonParser parser = new JsonParser();
    JsonArray Jarray = parser.parse(userdynlist).getAsJsonArray();

    for (JsonElement obj : Jarray) {
        HomeAttentionUserListBean homeAttentionUserListBean = gson.fromJson(obj, HomeAttentionUserListBean.class);

        mAttentionList2.add(homeAttentionUserListBean);
    }
    mAdapter.addData(mAttentionList2);

}

@Override
public void loadMoreFail() {
    layoutRefresh.finishLoadMore(false);
}

@Override
public void onError() {
    layoutRefresh.finishLoadMore(false);
    layoutLoading.setStatus(LoadingLayout.ERROR);
}

@Override
public void noNetwork() {
    layoutRefresh.finishLoadMore(false);
    layoutLoading.setStatus(LoadingLayout.NO_NETWORK);
}

@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
    currentPage++;
    getMoreDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
    currentPage = 1;
    getDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    HomeAttentionUserListBean homeBean = mAdapter.getData().get(position);
    Intent intent = new Intent();
    switch (mAdapter.getItemViewType(position)) {
        case HomeAttentionUserListBean.TYPE_SHUFA://书法

            //方法2 带动画的跳转
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName = "transition_image";
            int authorid = homeBean.getAuthorid();
            int versionId = homeBean.getVersionId();
            ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle = compat.toBundle();
            if (bundle != null) {
                bundle.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle.putString("authorPic", homeBean.getAuthorpic());
                bundle.putString("userName", homeBean.getUserName());
                bundle.putString("authorid", String.valueOf(authorid));
                bundle.putString("worksName", homeBean.getProductName());//作品名
                bundle.putString("des", homeBean.getDes());//描述
                bundle.putString("versionId", String.valueOf(versionId));
                bundle.putString("productId", String.valueOf(homeBean.getId()));
                bundle.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle);
            ActivityCompat.startActivity(getContext(), intent, bundle);

            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画

            //方法2 带动画的跳转
            int[] location1 = new int[2];
            view.getLocationOnScreen(location1);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName1 = "transition_image";
            int authorid1 = homeBean.getAuthorid();
            int versionId1 = homeBean.getVersionId();
            ActivityOptionsCompat compat1 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName1);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle1 = compat1.toBundle();
            if (bundle1 != null) {
                bundle1.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle1.putString("authorPic", homeBean.getAuthorpic());
                bundle1.putString("userName", homeBean.getUserName());
                bundle1.putString("authorid", String.valueOf(authorid1));
                bundle1.putString("worksName", homeBean.getProductName());//作品名
                bundle1.putString("des", homeBean.getDes());//描述
                bundle1.putString("versionId", String.valueOf(versionId1));
                bundle1.putString("productId", String.valueOf(homeBean.getId()));
                bundle1.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle1);
            ActivityCompat.startActivity(getContext(), intent, bundle1);

            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章

            //方法2 带动画的跳转
            int[] location2 = new int[2];
            view.getLocationOnScreen(location2);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName2 = "transition_image";
            int authorid2 = homeBean.getAuthorid();
            int versionId2 = homeBean.getVersionId();
            ActivityOptionsCompat compat2 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName2);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle2 = compat2.toBundle();
            if (bundle2 != null) {
                bundle2.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle2.putString("authorPic", homeBean.getAuthorpic());
                bundle2.putString("userName", homeBean.getUserName());
                bundle2.putString("authorid", String.valueOf(authorid2));
                bundle2.putString("worksName", homeBean.getName());//作品名
                bundle2.putString("des", homeBean.getDes());//描述
                bundle2.putString("versionId", String.valueOf(versionId2));
                bundle2.putString("productId", String.valueOf(homeBean.getId()));
                bundle2.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle2);
            ActivityCompat.startActivity(getContext(), intent, bundle2);

            break;
        case HomeAttentionUserListBean.TYPE_BOOKS://书籍
            //方法2 带动画的跳转
            int[] location3 = new int[2];
            view.getLocationOnScreen(location3);
            intent.setClass(getContext(), HomeImageDetailActivity.class);
            String optionName3 = "transition_image";
            int authorid3 = homeBean.getAuthorid();
            int versionId3 = homeBean.getVersionId();
            ActivityOptionsCompat compat3 = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, optionName3);
            //利用Bundle将点击的图片的网址传递过去
            Bundle bundle3 = compat3.toBundle();
            if (bundle3 != null) {
                bundle3.putString(HomeImageDetailActivity.IMAGE_TAG, homeBean.getPicture());
                bundle3.putString("authorPic", homeBean.getAuthorpic());
                bundle3.putString("userName", homeBean.getUserName());
                bundle3.putString("authorid", String.valueOf(authorid3));
                bundle3.putString("worksName", homeBean.getName());//作品名
                bundle3.putString("des", homeBean.getDes());//描述
                bundle3.putString("versionId", String.valueOf(versionId3));
                bundle3.putString("productId", String.valueOf(homeBean.getId()));
                bundle3.putString("updateTime",homeBean.getCreatetime());
            }
            intent.putExtras(bundle3);
            ActivityCompat.startActivity(getContext(), intent, bundle3);

            break;

        case HomeAttentionUserListBean.TYPE_VIDEOS://视频

            String productId_videos = String.valueOf(homeBean.getId());
            String authorId = String.valueOf(homeBean.getAuthorid());
            String scale = homeBean.getScale();
            String versionid = String.valueOf(homeBean.getVersionId());
            intent.setClass(getActivity(), HomeVideoDetailActivity.class);
            intent.putExtra("productId", productId_videos);
            intent.putExtra("authorid", authorId);
            intent.putExtra("scale", scale);
            intent.putExtra("productName", homeBean.getProductName());
            intent.putExtra("versionId", versionid);
            startActivity(intent);
            break;
    }
}

@Override
public void onReload() {
    getDate(currentPage, pageSize, userId, sdate);
}

@Override
public void onEmpty() {
    layoutLoading.setStatus(LoadingLayout.EMPTY);
}

@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
    HomeAttentionUserListBean homeBean = mAdapter.getData().get(position);
    Intent intent = new Intent();
    switch (mAdapter.getItemViewType(position)) {

        case HomeAttentionUserListBean.TYPE_SHUFA://书法

            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  书法");
                }
            });
            break;

        case HomeAttentionUserListBean.TYPE_HUIHUA://绘画
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  会话");
                }
            });
            break;

        case HomeAttentionUserListBean.TYPE_ARTICLE://文章
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  文章");
                }
            });
            break;
        case HomeAttentionUserListBean.TYPE_BOOKS://书籍
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  书籍");
                }
            });

            break;

        case HomeAttentionUserListBean.TYPE_VIDEOS://视频
            mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    Log.d(TAG, "onItemChildClick: ");
                    ToastUtils.showToast("类型  视频");
                }
            });
            ToastUtils.showToast("类型  视频");

            break;
    }
}

}

看来看去你的adapter只设置了OnItemClickListener,如果要监听item里面的view,还要设置OnItemChildClickListener

kris-liutao commented 5 years ago

嗯嗯 多谢了 这个问题解决了 我是 implements BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener, 两个接口的 结果第二个没监听到

CymChad commented 5 years ago

@Panxiaoan1993 感谢你的回复