分类列表——购物车

public class Classify extends Fragment implements IHomeView, IFenLeiView, MyFlAdapterLeft.CidListener {

    private View view;
    private RecyclerView mTypeRvleft;
    private RecyclerView mTypeRvright;
    private int num = 1;
    private PresenterImp presenterImp;
    private int myposition;
    private SimpleDraweeView mFlRightImge;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fenlei, container, false);
        initView(view);

        return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


        presenterImp = new PresenterImp();
        presenterImp.showFeiLeiToView(new ModleImp(), getActivity(), this);
        presenterImp.showFLRightToView(new ModleImp(), getActivity(), this, num);

    }

    private void initView(View view) {
        mTypeRvleft = (RecyclerView) view.findViewById(R.id.type_rvleft);
        mTypeRvright = (RecyclerView) view.findViewById(R.id.type_rvright);
        mFlRightImge = (SimpleDraweeView) view.findViewById(R.id.fl_right_imge);
    }



    @Override
    public void showFeiLeiDatas(List<Sy_FLBean.DataBean> data) {

        //        创建布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//      设置recyclerview
        mTypeRvleft.setLayoutManager(layoutManager);

        MyFlAdapterLeft adapter = new MyFlAdapterLeft(data, getActivity());
        mTypeRvleft.setAdapter(adapter);

        adapter.setCidInfo(new MyFlAdapterLeft.CidListener() {
            @Override
            public void getCids(int postion, int cid) {
//      刷新右边页面信息   
                presenterImp.showFLRightToView(new ModleImp(), getActivity(), Classify.this, cid);

            }
        });

    }



//  分类右边
    @Override
    public void showFLRightList(List<FlRightBean.DataBean> data) {


        //        创建布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//      设置recyclerview
        mTypeRvright.setLayoutManager(layoutManager);

        MyFlAdapterRight adapter = new MyFlAdapterRight(data, getActivity());
        mTypeRvright.setAdapter(adapter);


    }


    @Override
    public void getCids(int postion, int cid) {
        Log.d("Classify------------", "postion:" + postion);
    }
}

适配器———————————-

public class MyFlAdapterLeft extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    List<Sy_FLBean.DataBean> data;
    Context context;
    private CidListener cidListener;

    public MyFlAdapterLeft(List<Sy_FLBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.layout_recycler_left, null);
        return new MyViewHolder(view);
    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof MyViewHolder) {
            ((MyViewHolder) holder).title.setText(data.get(position).getName());
            ((MyViewHolder) holder).title.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int s = position;
//                    获取点击的cid
                    cidListener.getCids(s,data.get(position).getCid());
                }
            });

        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {


        public final TextView title;


        public MyViewHolder(View itemView) {
            super(itemView);

            title = itemView.findViewById(R.id.fl_left_title);

        }

    }

    //提供一个内部访问的方法
    public interface CidListener {
        void getCids(int postion,int cid);
    }

    //提供一个外部访问的方法
    public void setCidInfo(CidListener cidListener) {
        this.cidListener = cidListener;
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值