public class XiangActivityextends AppCompatActivityimplements MainView {
private ViewPagerviewpager;
private TextViewprcies,num,name;
private ImagesAdapteradapter;
private int intent;
private String[]picTrueArr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiang);
intent = getIntent().getIntExtra("id",101);
viewpager = (ViewPager) findViewById(R.id.imageso);
prcies = (TextView) findViewById(R.id.pric);
num = (TextView) findViewById(R.id.sum);
name = (TextView) findViewById(R.id.name);
MainPresenterIml mainPresenterIml =new MainPresenterIml(new MainModelIml(),this);
mainPresenterIml.doXiang(intent);
adapter =new ImagesAdapter();
viewpager.setAdapter(adapter);
}
@Override
public void success(String data) {
try {
JsonBean bean =new Gson().fromJson(data, JsonBean.class);
name.setText(bean.getResult().getCommodityName());
prcies.setText("¥" + bean.getResult().getPrice());
num.setText("已售" + bean.getResult().getSaleNum() +"件");
String picTrue = bean.getResult().getPicture();
picTrueArr = picTrue.split(",");
adapter.notifyDataSetChanged();
//Glide.with(this).load(bean.getResult().getPicture())
}catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void fail(String error) {
}
private class ImagesAdapterextends 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(XiangActivity.this);
Glide.with(XiangActivity.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);
}
}