Adater_left
public class Adater_fenlei extends RecyclerView.Adapter<Adater_fenlei.MyHolder>{ private List<Bean1.DataBean> list; private Context context; setOn setOnItemListener; public void setSetOnItemListener(setOn setOnItemListener) { this.setOnItemListener = setOnItemListener; } public interface setOn{ void setOnItem(int i,View view,int cid); } public Adater_fenlei(List<Bean1.DataBean> list, Context context) { this.list = list; this.context = context; } @Override public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.fenlei_left, null); MyHolder holder = new MyHolder(view); return holder; } @Override public void onBindViewHolder(MyHolder holder, final int position) { holder.name.setText(list.get(position).getName()+""); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int cid = list.get(position).getCid(); setOnItemListener.setOnItem(position,view,cid); } }); } @Override public int getItemCount() { return list.size(); } public class MyHolder extends RecyclerView.ViewHolder{ private final TextView name; public MyHolder(View itemView) { super(itemView); name = (TextView) itemView.findViewById(R.id.name); } } }
Adater_right 1:
public class MyAdater extends RecyclerView.Adapter<MyAdater.MyHolder>{ private List<Bean2.DataBean.ListBean> list; private Context context; setOn setOnItemClick; public MyAdater(List<Bean2.DataBean.ListBean> list, Context context) { this.list = list; this.context = context; } public interface setOn{ void setOnItem(int i,View view,int pscid); } public void setSetOnItemClick(setOn setOnItemClick) { this.setOnItemClick = setOnItemClick; } @Override public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.feilei_right, null); MyHolder holder = new MyHolder(view); return holder; } @Override public void onBindViewHolder(MyHolder holder, final int position) { ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.displayImage(list.get(position).getIcon(),holder.img); holder.name.setText(list.get(position).getName()); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int pscid = list.get(position).getPscid(); setOnItemClick.setOnItem(position,v,pscid); } }); } @Override public int getItemCount() { return list.size(); } public class MyHolder extends RecyclerView.ViewHolder{ private final ImageView img; private final TextView name; public MyHolder(View itemView) { super(itemView); img = (ImageView) itemView.findViewById(R.id.img); name = (TextView) itemView.findViewById(R.id.name); } } }
Adater 2 :
public class Right_Adater extends RecyclerView.Adapter<Right_Adater.MyHolder> { private List<Bean2.DataBean> list; private Context context; public Right_Adater(List<Bean2.DataBean> list, Context context) { this.list = list; this.context = context; } @Override public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.item_righit, null); MyHolder myHolder = new MyHolder(view); return myHolder; } @Override public void onBindViewHolder(MyHolder holder, int position) { holder.name.setText(list.get(position).getName()); MyAdater myAdapter = new MyAdater(list.get(position).getList(), context); GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3); holder.rlv.setLayoutManager(gridLayoutManager); holder.rlv.setAdapter(myAdapter); myAdapter.setSetOnItemClick( new MyAdater.setOn() { @Override public void setOnItem(int i, View view, int pscid) { Toast.makeText(context,pscid+"",Toast.LENGTH_SHORT).show(); Intent intent=new Intent(context, ListActivity.class); intent.putExtra("pscid",pscid); context.startActivity(intent); } }); } @Override public int getItemCount() { return list.size(); } public class MyHolder extends RecyclerView.ViewHolder{ private final TextView name; private final RecyclerView rlv; public MyHolder(View itemView) { super(itemView); name = (TextView) itemView.findViewById(R.id.name); rlv = (RecyclerView) itemView.findViewById(R.id.rlv); } } }
zhu:
public class MainActivity extends AppCompatActivity implements IView, com.example.dell.feilei.fenlei_right.v.IView{ private MyPresenter presenter; private RecyclerView rlv; private Adater_fenlei adater_fenlei; private Pre pre; private RecyclerView rlv1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rlv = (RecyclerView) findViewById(R.id.leftRlv); rlv1 = (RecyclerView) findViewById(R.id.rightRlv); presenter = new MyPresenter(this); presenter.getDate(); pre = new Pre(this); } @Override public void chenggong(Bean1 bean1) { List<Bean1.DataBean> data = bean1.getData(); adater_fenlei = new Adater_fenlei(data, this); LinearLayoutManager layoutManager = new LinearLayoutManager(this); rlv.setLayoutManager(layoutManager); rlv.setAdapter(adater_fenlei); adater_fenlei.setSetOnItemListener(new Adater_fenlei.setOn() { private Map<String, String> map; @Override public void setOnItem(int i, View view, int cid) { map = new HashMap<>(); map.put("cid","1"); pre.getDate("https://www.zhaoapi.cn/product/getProductCatagory",map); } }); } @Override public void shibai(Bean1 bean1) { } @Override public void chenggong(Bean2 bean2) { List<Bean2.DataBean> data = bean2.getData(); Right_Adater adater=new Right_Adater(data,MainActivity.this); LinearLayoutManager layoutManager = new LinearLayoutManager(this); rlv1.setLayoutManager(layoutManager); rlv1.setAdapter(adater); } @Override public void shibai(Bean2 bean2) { } }