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;
}
}