public class RxxpAdapter extends RecyclerView.Adapter
private Context context;
private List al = new ArrayList<>();
public RxxpAdapter(Context context) {
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(context, R.layout.rxxp_item, null);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
viewHolder.title.setText(al.get(i).getCommodityName());
viewHolder.price.setText(al.get(i).getMasterPic());
Glide.with(context).load(al.get(i).getMasterPic()).into(viewHolder.image);
//点击详情页面
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, XiangQingActivity.class);
intent.putExtra("id",al.get(i).getCommodityId());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return al.size();
}
public void setData(List list) {
this.al = list;
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView title, price;
ImageView image;
public ViewHolder(@NonNull View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.rxxp_title);
price = (TextView) itemView.findViewById(R.id.rxxp_price);
image = (ImageView) itemView.findViewById(R.id.rxxp_img);
}
}
}
public class MlssAdapter extends RecyclerView.Adapter
private Context context;
private List list = new ArrayList<>();
public MlssAdapter(Context context) {
this.context = context;
}
@NonNull
@Override
public MlssViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(context, R.layout.mlss_item, null);
MlssViewHolder holder = new MlssViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull MlssViewHolder viewHolder, final int i) {
viewHolder.title.setText(list.get(i).getCommodityName());
viewHolder.price.setText("¥" + list.get(i).getPrice());
Glide.with(context).load(list.get(i).getMasterPic()).into(viewHolder.iamge);
Toast.makeText(context, list.get(i).toString(), Toast.LENGTH_LONG).show();
//点击详情页面
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, XiangQingActivity.class);
intent.putExtra("id",list.get(i).getCommodityId());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
// 传递数据
public void setData(List al) {
this.list = al;
notifyDataSetChanged();
}
public class MlssViewHolder extends RecyclerView.ViewHolder {
TextView title, price;
ImageView iamge;
public MlssViewHolder(@NonNull View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.tv_title);
price = (TextView) itemView.findViewById(R.id.price);
iamge = (ImageView) itemView.findViewById(R.id.image_view);
}
}
}
public class PzshAdapter extends RecyclerView.Adapter
private Context context;
private List list = new ArrayList<>();
public PzshAdapter(Context context) {
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(context, R.layout.pzsh_item, null);
ViewHolder holder = new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
viewHolder.title.setText(list.get(i).getCommodityName());
viewHolder.price.setText("¥" + list.get(i).getPrice());
Glide.with(context).load(list.get(i).getMasterPic()).into(viewHolder.iamge);
//点击详情页面
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, XiangQingActivity.class);
intent.putExtra("id",list.get(i).getCommodityId());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
//传递数据
public void setData(List al) {
this.list = al;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView title, price;
ImageView iamge;
public ViewHolder(@NonNull View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.tv_title);
price = (TextView) itemView.findViewById(R.id.price);
iamge = (ImageView) itemView.findViewById(R.id.image_view);
}
}
}
public class XiangQingActivity extends AppCompatActivity implements ShowView {
private ViewPager mImage;
private TextView mPrice, mNum, mTitle;
private String[] picTrueArr;
private ImagePageAdapter imagePageAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiang_qing);
//初始化
int id = getIntent().getIntExtra("id", 103);
ShowPresenterIml mainPresenterIml = new ShowPresenterIml(new ShowModelIml(), this);
mainPresenterIml.doShopDetail(0,id + "");
mImage = (ViewPager) findViewById(R.id.viewpage);
mPrice = (TextView) findViewById(R.id.tv_price);
mNum = (TextView) findViewById(R.id.tv_num);
mTitle = (TextView) findViewById(R.id.tv_title);
imagePageAdapter = new ImagePageAdapter();
mImage.setAdapter(imagePageAdapter);
}
@Override
public void success(int type, String data) {
try {
ShopDetailBean bean = new Gson().fromJson(data, ShopDetailBean.class);
mTitle.setText(bean.getResult().getCommodityName());
mPrice.setText("¥" + bean.getResult().getPrice());
mNum.setText("已售" + bean.getResult().getSaleNum() + "件");
String picTrue = bean.getResult().getPicture();
picTrueArr = picTrue.split(",");
imagePageAdapter.notifyDataSetChanged();
//Glide.with(this).load(bean.getResult().getPicture())
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void fail(String error) {
}
private class ImagePageAdapter extends PagerAdapter {
@Override
public int getCount() {
if (picTrueArr == null) {
return 0;
}
return picTrueArr.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view == o;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ImageView imageView = new ImageView(XiangQingActivity.this);
Glide.with(XiangQingActivity.this).load(picTrueArr[position]).into(imageView);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
}