购物车详情

GoodsxiangqingActivity:
public class GoodsxiangqingActivity extends AppCompatActivity implements IGoodsView,IAddView {

    private ImageView xiangqing_image;
    private TextView xiangqing_price;
    private TextView xiangqing_title;
    private int uid=10863;
    private GoodsPresenter goodsPresenter;
    private AddGouwuchePresenter addGouwuchePresenter;
    private int pid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goodsxiangqing);
        xiangqing_image = (ImageView) findViewById(R.id.xiangqing_image);
        xiangqing_price = (TextView) findViewById(R.id.xiangqing_price);
        xiangqing_title = (TextView) findViewById(R.id.xiangqing_title);
        final Intent intent = getIntent();
        int pid = intent.getIntExtra("pid", 0);
        goodsPresenter = new GoodsPresenter(this);
        goodsPresenter.getGoods("https://www.zhaoapi.cn/product/getProductDetail",pid);


    }

    @Override
    public void postGoods(final GoodsxiangqingBean goodsxiangqingBean) {
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  pid = goodsxiangqingBean.getData().getPid();
                  xiangqing_title.setText(goodsxiangqingBean.getData().getTitle());
                  xiangqing_price.setText(""+goodsxiangqingBean.getData().getPrice());
                  Glide.with(GoodsxiangqingActivity.this).load(goodsxiangqingBean.getData().getImages()).into(xiangqing_image);

                  xiangqing_image.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Intent intent1=new Intent(GoodsxiangqingActivity.this,ZhaopianActivity.class);
                          intent1.putExtra("image",goodsxiangqingBean.getData().getImages());
                          startActivity(intent1);
                      }
                  });

              }
          });

    }

//点击按钮返回
    public void getfanhui(View view) {
        finish();
    }
//加入购物车
    public void addCart(View view) {
        addGouwuchePresenter = new AddGouwuchePresenter(this);
        addGouwuchePresenter.getAdd("https://www.zhaoapi.cn/product/addCart",uid,pid);
    }

    @Override
    public void postAdd(final AddGouwucheBean addGouwucheBean) {
           runOnUiThread(new Runnable() {
               @Override
               public void run() {
                   int i= Integer.parseInt(addGouwucheBean.getCode());
                   if(i==0){
                       Toast.makeText(GoodsxiangqingActivity.this,"添加成功",Toast.LENGTH_SHORT).show();
                   }else{
                       Toast.makeText(GoodsxiangqingActivity.this,"添加失败",Toast.LENGTH_SHORT).show();
                   }
               }
           });
    }
}
GoodsxiangqingActivity布局:
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.jingdong_xiangmu01.activity.GoodsxiangqingActivity"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_weight="1"
        android:paddingTop="10dp"
        android:orientation="horizontal">

        <Button
            android:onClick="getfanhui"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="9"
            android:background="@drawable/leftjiantou" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
            android:layout_weight="1"
            android:text="商品"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="9"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/xiangqing_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/xiangqing_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/xiangqing_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#f00" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3"/>

        <Button
            android:onClick="addCart"
            android:background="#f00"
            android:text="加入购物车"
            android:textColor="#fff"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3" />


    </LinearLayout>

</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值