首页点击后跳转到的页面

package com.bawei.yuezkao1.view.activity;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bawei.yuezkao1.R;
import com.bawei.yuezkao1.model.bean.HomeshopsBean;
import com.facebook.drawee.view.SimpleDraweeView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.realm.Realm;

public class Main2Activity extends AppCompatActivity {

    @BindView(R.id.simple_id)
    SimpleDraweeView simpleId;
    @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 homeshopsBean;
    private Realm realm;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        unbinder = ButterKnife.bind(this);
        //获取数据库的实例
        realm = Realm.getDefaultInstance();

    }

    @OnClick(R.id.shopCart_id)
    public void onViewClicked() {
        //点击添加商品到购物车,实际上就是添加到数据库
        realm.beginTransaction();//开启事务
        realm.copyToRealm(homeshopsBean);//向数据库中添加(不会更新数据)
        realm.commitTransaction();//提交事务
        Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();

    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void receive(HomeshopsBean homeshopsBean) {
        this.homeshopsBean = homeshopsBean;
        bookname.setText(homeshopsBean.getBookname());
        appearance.setText(homeshopsBean.getAppearance());
        location.setText(homeshopsBean.getLocation());

        String[] images = homeshopsBean.getImages().split(",");
        simpleId.setImageURI(images[0]);
        shopinfo.setText(homeshopsBean.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();
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值