parent
622cd6a086
commit
0d662c0ad6
@ -0,0 +1,85 @@
|
|||||||
|
package com.example.catapp.fragment;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentTransaction;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.catapp.R;
|
||||||
|
import com.example.catapp.activity.IndexActivity;
|
||||||
|
import com.example.catapp.adapter.ShopAdapter;
|
||||||
|
import com.example.catapp.entity.ShoppingCartPack;
|
||||||
|
import com.example.catapp.netrequest.OkHttpShoppingcart;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ProductDetailFragment extends Fragment implements View.OnClickListener{
|
||||||
|
ImageView imageView;
|
||||||
|
TextView textView1,textView2;
|
||||||
|
Button buttonAdd,buttonSale;
|
||||||
|
LinearLayout line1,line2,line3;
|
||||||
|
int p;
|
||||||
|
int userid;
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = LayoutInflater.from(getActivity()).inflate(R.layout.good_detail, container, false);
|
||||||
|
init(view);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
private void init(View view){
|
||||||
|
imageView=view.findViewById(R.id.category_product_image);
|
||||||
|
textView1=view.findViewById(R.id.category_product_name);
|
||||||
|
textView2=view.findViewById(R.id.category_product_price);
|
||||||
|
buttonAdd=view.findViewById(R.id.buttonA);
|
||||||
|
buttonAdd.setOnClickListener(this);
|
||||||
|
buttonSale=view.findViewById(R.id.buttonS);
|
||||||
|
line1=view.findViewById(R.id.li1);
|
||||||
|
line2=view.findViewById(R.id.li2);
|
||||||
|
line3=view.findViewById(R.id.li3);
|
||||||
|
setData();
|
||||||
|
}
|
||||||
|
private void setData() {
|
||||||
|
Bundle bundle = getArguments();
|
||||||
|
imageView.setImageBitmap(bundle.getParcelable("imgBitmap"));
|
||||||
|
textView1.setText(bundle.getString("name"));
|
||||||
|
textView2.setText(bundle.getString("price"));
|
||||||
|
p=bundle.getInt("productId");
|
||||||
|
userid=bundle.getInt("userId");
|
||||||
|
Log.d("p","u"+userid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.buttonA:
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
OkHttpShoppingcart okHttpShoppingcart=new OkHttpShoppingcart();
|
||||||
|
try {
|
||||||
|
okHttpShoppingcart.addShoppingCart(userid,p);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<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:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/li1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="139dp"
|
||||||
|
android:background="#ffffff"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/category_product_image"
|
||||||
|
android:layout_width="70dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/li2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="6"
|
||||||
|
android:background="#1EFFFFFF"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/category_product_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:text="商品名称"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/category_product_price"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:text="价格" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/li3"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonA"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_login"
|
||||||
|
android:text="加入购物车"
|
||||||
|
android:textColor="#fff"
|
||||||
|
android:textSize="18sp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonS"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginLeft="40dp"
|
||||||
|
android:background="@drawable/button_login"
|
||||||
|
android:text="购买"
|
||||||
|
android:textColor="#fff"
|
||||||
|
android:textSize="18sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -1,70 +1,83 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#14FFEB3B"
|
android:background="#14FFEB3B"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
>
|
>
|
||||||
|
|
||||||
<ImageView
|
<LinearLayout
|
||||||
android:id="@+id/category_product_image"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="80dp"
|
android:layout_height="139dp"
|
||||||
android:layout_height="80dp"
|
android:orientation="horizontal">
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="5dp" />
|
|
||||||
|
|
||||||
<TextView
|
<CheckBox
|
||||||
android:id="@+id/category_product_name"
|
android:id="@+id/checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="46dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_toRightOf="@+id/category_product_image"
|
android:layout_weight="1" />
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginTop="25dp"
|
|
||||||
android:textColor="#050505"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:id="@+id/category_product_price"
|
android:id="@+id/category_product_image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="111dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_toRightOf="@+id/category_product_name"
|
android:layout_marginLeft="5dp"
|
||||||
android:layout_gravity="center"
|
android:layout_weight="1" />
|
||||||
android:layout_marginLeft="60dp"
|
|
||||||
android:layout_marginTop="25dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="#050505"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/left"
|
|
||||||
android:layout_width="36dp"
|
|
||||||
android:layout_height="36dp"
|
|
||||||
android:layout_marginLeft="40dp"
|
|
||||||
android:layout_marginTop="55dp"
|
|
||||||
android:layout_toRightOf="@id/category_product_price"
|
|
||||||
android:background="@drawable/left"
|
|
||||||
|
|
||||||
/>
|
<LinearLayout
|
||||||
<TextView
|
android:layout_width="wrap_content"
|
||||||
android:id="@+id/num"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_weight="6"
|
||||||
android:layout_height="40dp"
|
android:background="#1EFFFFFF"
|
||||||
android:layout_toRightOf="@+id/left"
|
android:orientation="vertical">
|
||||||
android:layout_marginLeft="20dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="#00FEFEFE"
|
|
||||||
android:textColor="#050505"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/right"
|
|
||||||
android:layout_width="48dp"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginLeft="20dp"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:layout_toRightOf="@id/num"
|
|
||||||
android:background="@drawable/right"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
<TextView
|
||||||
|
android:id="@+id/category_product_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:text="商品名称"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/category_product_price"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:text="价格" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/left"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_marginTop="100dp"
|
||||||
|
android:layout_toRightOf="@id/category_product_price"
|
||||||
|
android:background="@drawable/left" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/num"
|
||||||
|
android:layout_width="18dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginTop="50dp"
|
||||||
|
android:layout_toRightOf="@+id/left"
|
||||||
|
android:background="#00FEFEFE"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="#050505"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/right"
|
||||||
|
android:layout_width="42dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:layout_marginTop="50dp"
|
||||||
|
android:layout_toRightOf="@id/num"
|
||||||
|
android:background="@drawable/right" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue