public class MyAdapt extends XRecyclerView.Adapter<RecyclerView.ViewHolder>{
public static final int a=0;
public static final int b=1;
private List<Baen.DataBeanX.DataBean> data =new ArrayList<>();
private View view;
private String s;
private String s1;
private String s2;
public MyAdapt(List<Baen.DataBeanX.DataBean> data) {
this.data = data;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType==a){
view = View.inflate(parent.getContext(), R.layout.itme01, null);
return new MyViewHoderOne(view);
}else {
view = View.inflate(parent.getContext(), R.layout.itme02, null);
return new MyViewHoderTwo(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int itemViewType = getItemViewType(position);
switch (itemViewType){
case a:
((MyViewHoderOne) holder).itme_text.setText(data.get(position).getTitle());
String link = data.get(position).getPics().get(0);
ImageLoader.getInstance().displayImage(link,((MyViewHoderOne) holder).itme01_ima,MyApp.getOptions());
break;
case b:
Log.d("Tat","leng"+data.get(position).getPics().size());
s = data.get(position).getPics().get(0);
String ss="http://365jia.cn/uploads/"+s;
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima01,MyApp.getOptions());
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima02,MyApp.getOptions());
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima03,MyApp.getOptions());
break;
}
}
@Override
public int getItemCount() {
return data==null?0:data.size();
}
public class MyViewHoderOne extends XRecyclerView.ViewHolder{
private final ImageView itme01_ima;
private final TextView itme_text;
public MyViewHoderOne(View itemView) {
super(itemView);
itme01_ima = itemView.findViewById(R.id.itme01_ima);
itme_text = itemView.findViewById(R.id.item01_text);
}
}
public class MyViewHoderTwo extends XRecyclerView.ViewHolder{
private final ImageView itme02_ima01,itme02_ima02,itme02_ima03;
public MyViewHoderTwo(View itemView) {
super(itemView);
itme02_ima01 = itemView.findViewById(R.id.itme02_ima01);
itme02_ima02 = itemView.findViewById(R.id.itme02_ima02);
itme02_ima03 = itemView.findViewById(R.id.itme02_ima03);
}
}
@Override
public int getItemViewType (int position) {
List<String> pics = data.get(position).getPics();
int size = pics.size();
if (size==0){
return a;
}else {
return b;
}
}
public static final int a=0;
public static final int b=1;
private List<Baen.DataBeanX.DataBean> data =new ArrayList<>();
private View view;
private String s;
private String s1;
private String s2;
public MyAdapt(List<Baen.DataBeanX.DataBean> data) {
this.data = data;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType==a){
view = View.inflate(parent.getContext(), R.layout.itme01, null);
return new MyViewHoderOne(view);
}else {
view = View.inflate(parent.getContext(), R.layout.itme02, null);
return new MyViewHoderTwo(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int itemViewType = getItemViewType(position);
switch (itemViewType){
case a:
((MyViewHoderOne) holder).itme_text.setText(data.get(position).getTitle());
String link = data.get(position).getPics().get(0);
ImageLoader.getInstance().displayImage(link,((MyViewHoderOne) holder).itme01_ima,MyApp.getOptions());
break;
case b:
Log.d("Tat","leng"+data.get(position).getPics().size());
s = data.get(position).getPics().get(0);
String ss="http://365jia.cn/uploads/"+s;
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima01,MyApp.getOptions());
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima02,MyApp.getOptions());
ImageLoader.getInstance().displayImage(ss,((MyViewHoderTwo) holder).itme02_ima03,MyApp.getOptions());
break;
}
}
@Override
public int getItemCount() {
return data==null?0:data.size();
}
public class MyViewHoderOne extends XRecyclerView.ViewHolder{
private final ImageView itme01_ima;
private final TextView itme_text;
public MyViewHoderOne(View itemView) {
super(itemView);
itme01_ima = itemView.findViewById(R.id.itme01_ima);
itme_text = itemView.findViewById(R.id.item01_text);
}
}
public class MyViewHoderTwo extends XRecyclerView.ViewHolder{
private final ImageView itme02_ima01,itme02_ima02,itme02_ima03;
public MyViewHoderTwo(View itemView) {
super(itemView);
itme02_ima01 = itemView.findViewById(R.id.itme02_ima01);
itme02_ima02 = itemView.findViewById(R.id.itme02_ima02);
itme02_ima03 = itemView.findViewById(R.id.itme02_ima03);
}
}
@Override
public int getItemViewType (int position) {
List<String> pics = data.get(position).getPics();
int size = pics.size();
if (size==0){
return a;
}else {
return b;
}
}
}
public class MainActivity extends AppCompatActivity { String urlleft="https://www.zhaoapi.cn/product/getCatagory"; private XRecyclerView xRecyclerView; private int page; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); xRecyclerView = findViewById(R.id.xrecyclerview); Okhttutlis.getInstance().doGet(urlleft, new Okhttutlis.OkCallback() { @Override public void onFailure(Exception e) { } @Override public void onResponse(String json) { Gson gson = new Gson(); LeftBaen leftBaen = gson.fromJson(json, LeftBaen.class); String code = leftBaen.getCode(); if (code.equals("0")){ final List<LeftBaen.DataBean> data = leftBaen.getData(); MyAdapter myAdapter = new MyAdapter(data); xRecyclerView.setAdapter(myAdapter); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this); xRecyclerView.setLayoutManager(linearLayoutManager); xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() { @Override public void onRefresh() { xRecyclerView.refreshComplete(); } @Override public void onLoadMore() { page+=10; xRecyclerView.refreshComplete(); } }); } } }); } }