在这里插入代码片
```public class DetailActivity extends AppCompatActivity {
@BindView(R.id.image)
SimpleDraweeView image;
@BindView(R.id.bookname)
TextView bookname;
@BindView(R.id.appearance)
TextView appearance;
@BindView(R.id.location)
TextView location;
@BindView(R.id.shopinfo)
TextView shopinfo;
private Unbinder unbinder;
private HomeshopsBean homeshopBean;
private Realm realm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
unbinder = ButterKnife.bind(this);
//获取数据库的实例
realm = Realm.getDefaultInstance();
}
@OnClick(R.id.shopCart)
public void onViewClicked() {
//点击添加商品到购物车,实际上就是添加到数据库
realm.beginTransaction();//开启事务
realm.copyToRealm(homeshopBean);//向数据库中添加(不会更新数据)
realm.commitTransaction();//提交事务
Toast.makeText(this, "添加成功!", Toast.LENGTH_SHORT).show();
}
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void receive(HomeshopsBean homeshopBean) {
this.homeshopBean = homeshopBean;
bookname.setText(homeshopBean.getBookname());
appearance.setText(homeshopBean.getAppearance());
location.setText(homeshopBean.getLocation());
String[] images = homeshopBean.getImages().split(",");
image.setImageURI(images[0]);
shopinfo.setText(homeshopBean.getShopinfo());
}
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
unbinder.unbind();
}
}
购物车的商品详情
最新推荐文章于 2022-11-22 23:06:00 发布