购物车的商品详情

在这里插入代码片
```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();
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值