MVP實現二級購物車
效果圖
使用介面:http://120.27.23.105/product/getCarts?uid=100
匯入依賴
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
清單檔案中加入許可權配置application的name屬性,ImageLoader初始化<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".appli.App"
</application>
public class App extends Application{ @Override public void onCreate() { super.onCreate(); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build(); ImageLoader.getInstance().init(configuration); } }
佈局中需要用到的的佈局,在drawable下面新建qujiesuan.xml
drawable下面還需要加入三張圖片<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="200dp"/> <solid android:color="#e53e42"/> <size android:height="60dp" android:width="130dp"/> </shape>
接下來就是activity_main.xml裡面的佈局,上面是recyclerView下面是一系列的功能
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_View"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:gravity="center_vertical"
android:padding="10dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:background="@drawable/shopcart_unselected"
android:button="@null"
android:id="@+id/quanxuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全選"
/>
<LinearLayout
android:padding="10dp"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:textColor="#e53e42"
android:id="@+id/total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="總價 : ¥0元"
/>
<TextView
android:id="@+id/total_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="共0件商品"
/>
</LinearLayout>
<TextView
android:gravity="center"
android:textSize="25sp"
android:text="去結算"
android:textColor="#fff"
android:background="@drawable/qujiesuan"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
自定義組合控制元件,,
custom_jiajian.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<Button
android:background="#fff"
android:textSize="20sp"
android:id="@+id/reverse"
android:text="一"
android:layout_width="50dp"
android:layout_height="wrap_content" />
<EditText
android:textStyle="bold"
android:textSize="23sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/count"
/>
<Button
android:id="@+id/add"
android:background="#fff"
android:textSize="25sp"
android:text="+"
android:layout_width="50dp"
android:layout_height="wrap_content" />
</LinearLayout>
介面卡的條目的佈局,recy_cart_item.xml
com.example.day20_mvp_cart.customView.CustomJiaJian 別忘了改成自己的包名下的,否則會報錯
recy_cart_item.xml,需要引入 自定義組合控制元件,在建立了CustomJiaJian類以後才可以引入
recy_cart_item.xml介面卡的佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="15dp"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/shop_checkbox"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:layout_marginLeft="20dp"
android:text="良品鋪子"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23sp"
android:textStyle="bold"
android:id="@+id/shop_name"
/>
</LinearLayout>
<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/item_face"
android:src="@mipmap/ic_launcher"
android:layout_width="120dp"
android:layout_height="120dp" />
<LinearLayout
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:id="@+id/item_name"
android:textSize="20sp"
android:text="三隻松鼠"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="0dp"
/>
<TextView
android:textColor="#f00"
android:id="@+id/item_price"
android:textSize="23sp"
android:text="299"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.example.day171122_cart.customview.CustomJiaJian
android:id="@+id/custom_jiajian"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
<ImageView
android:id="@+id/item_delete"
android:layout_marginRight="10dp"
android:src="@drawable/shopcart_delete"
android:layout_width="30dp"
android:layout_height="30dp" />
</LinearLayout>
</LinearLayout>
接著寫程式碼裡面的,首先將自定義組合控制元件的類填充在視圖裡
自定義組合控制元件的類,CustomJiaJian.java繼承LinearLayout,inflate填充佈局,+和-的點選事件回撥給adapter
CustomJiaJian.java
public class CustomJiaJian extends LinearLayout{
private Button reverse;
private Button add;
private EditText countEdit;
private int mCount =1;
public CustomJiaJian(Context context) {
super(context);
}
public CustomJiaJian(Context context, AttributeSet attrs) {
super(context, attrs);
View view = View.inflate(context, R.layout.custom_jiajian,this);
reverse = (Button) view.findViewById(R.id.reverse);
add = (Button) view.findViewById(R.id.add);
countEdit = (EditText) view.findViewById(R.id.count);
reverse.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String content = countEdit.getText().toString().trim();
int count = Integer.valueOf(content);
if(count>1){
mCount = count-1;
countEdit.setText(mCount+"");
//回撥給adapter裡面
if(customListener!=null){
customListener.jiajian(mCount);
}
}
}
});
add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String content = countEdit.getText().toString().trim();
int count = Integer.valueOf(content)+1;
mCount = count;
countEdit.setText(mCount+"");
//介面回撥給adapter
if(customListener!=null){
customListener.jiajian(mCount);
}
}
});
}
public CustomJiaJian(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
CustomListener customListener;
public void setCustomListener(CustomListener customListener){
this.customListener = customListener;
}
//加減的介面
public interface CustomListener{
public void jiajian(int count);
public void shuRuZhi(int count);
}
//這個方法是供recyadapter設定 數量時候呼叫的
public void setEditText(int num) {
if(countEdit !=null) {
countEdit.setText(num + "");
}
}
}
下面就是okhttp二次封裝的類,這裡就不詳細敘述了,詳見okhttp封裝類,攔截器地址
根據最上面給出的介面.訪問到的資料,生成一個實體類CartBean
在CartBean類裡面自己新增三個欄位,isFirst,item_check,shop_check
//自己新增的三個欄位
private int isFirst = 1;//1為顯示商鋪, 2為隱藏商鋪
private boolean item_check;//每個商品的選中狀態
private boolean shop_check;//商店的選中狀態
public int getIsFirst() {
return isFirst;
}
public void setIsFirst(int isFirst) {
this.isFirst = isFirst;
}
public boolean isItem_check() {
return item_check;
}
public void setItem_check(boolean item_check) {
this.item_check = item_check;
}
public boolean isShop_check() {
return shop_check;
}
public void setShop_check(boolean shop_check) {
this.shop_check = shop_check;
}
接下來就是使用MVP架構模式..首先建立presenter和model層,View這裡預設就是MainActivity
寫兩個介面,一個是ModelCallBack是model層的回撥介面,ViewCallBack是view層的回撥介面
ModelCallBack.java
public interface ModelCallBack {
public void success(CartBean cartBean);
public void failure(Exception e);
}
ViewCallBack.java
public interface ViewCallBack {
public void success(CartBean cartBean);
public void failure(Exception e);
}
下面是重要的MainActivity.java, 呼叫presenter層的方法,實現view層的介面的方法,還呼叫介面卡adapter裡面的介面
public class MainActivity extends AppCompatActivity implements ViewCallBack{
private RecyclerView recyclerView;
private TextView total_price;
private TextView total_num;
private CheckBox quanxuan;
private MyPresenter myPresenter;
private RecyAdapter recyAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//http://120.27.23.105/product/getCarts?uid=100
recyclerView = (RecyclerView) findViewById(R.id.recycler_View);
total_price = (TextView) findViewById(R.id.total_price);
total_num = (TextView) findViewById(R.id.total_num);
quanxuan = (CheckBox) findViewById(R.id.quanxuan);
quanxuan.setTag(1);//1為不選中
LinearLayoutManager manager = new LinearLayoutManager(MainActivity.this,LinearLayoutManager.VERTICAL,false);
//new出介面卡
recyAdapter = new RecyAdapter(this);
myPresenter = new MyPresenter(this);
//呼叫presenter裡面的請求資料的方法
myPresenter.getData();
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(recyAdapter);
//呼叫recyAdapter裡面的介面,設定 全選按鈕 總價 總數量
recyAdapter.setUpdateListener(new RecyAdapter.UpdateListener() {
@Override
public void setTotal(String total, String num, boolean allCheck) {
//設定ui的改變
total_num.setText("共"+num+"件商品");//總數量
total_price.setText("總價 :¥"+total+"元");//總價
if(allCheck){
quanxuan.setTag(2);
quanxuan.setBackgroundResource(R.drawable.shopcart_selected);
}else{
quanxuan.setTag(1);
quanxuan.setBackgroundResource(R.drawable.shopcart_unselected);
}
quanxuan.setChecked(allCheck);
}
});
//這裡只做ui更改, 點選全選按鈕,,調到adapter裡面操作
quanxuan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//呼叫adapter裡面的方法 ,,把當前quanxuan狀態傳遞過去
int tag = (int) quanxuan.getTag();
if(tag==1){
quanxuan.setTag(2);
quanxuan.setBackgroundResource(R.drawable.shopcart_selected);
}else{
quanxuan.setTag(1);
quanxuan.setBackgroundResource(R.drawable.shopcart_unselected);
}
recyAdapter.quanXuan(quanxuan.isChecked());
}
});
}
//實現介面,重寫的方法
@Override
public void success(CartBean cartBean) {
//拿到返回來的資料 ,, 傳給介面卡資料
recyAdapter.add(cartBean);
}
@Override
public void failure(final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"error",Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
//呼叫p層的解除繫結
myPresenter.detach();
}
}
MyPresenter.java,presenter層裡面 呼叫model層的方法,,防止記憶體洩露解綁
public class MyPresenter {
MyModel myModel = new MyModel();
ViewCallBack viewCallBack;
public MyPresenter(ViewCallBack viewCallBack) {
this.viewCallBack = viewCallBack;
}
//呼叫model 層的請求資料
public void getData(){
myModel.getData(new ModelCallBack() {
@Override
public void success(CartBean cartBean) {
if(viewCallBack!=null) {
viewCallBack.success(cartBean);
}
}
@Override
public void failure(Exception e) {
if(viewCallBack!=null) {
viewCallBack.failure(e);
}
}
});
}
/**
* 防止記憶體洩露
* */
public void detach(){
viewCallBack=null;
}
}
MyModel.java,model層裡面 呼叫okhttp的封裝類 單例模式,請求網路資料.返回一個bean類,型別改成CartBean
上面已經放過了MainActivity接收到model傳給presenter.presenter傳給view
的CartBean以後,將資料新增給介面卡,
public class MyModel {
public void getData(final ModelCallBack modelCallBack){
//訪問介面
String path = "http://120.27.23.105/product/getCarts?uid=100";
OkhttpUtils.getInstance().asy(null, path, new AbstractUiCallBack<CartBean>() {
@Override
public void success(CartBean cartBean) {
modelCallBack.success(cartBean);
}
@Override
public void fail(Exception e) {
modelCallBack.failure(e);
}
});
}
}
下面是介面卡RecyAdapter.java 這裡面的操作量就很大,包括了對每個條目的一系列操作,刪除,選中,和對自定義檢視加減號改變數量等,和是否顯示和隱藏一級商家的資訊,求總價,總數量等,部分操作也用到了介面回調出去
public class RecyAdapter extends RecyclerView.Adapter<RecyAdapter.MyViewHolder>{
Context context;
//建立大的集合
private List<CartBean.DataBean.ListBean> list;
//存放商家的id和商家的名稱的map集合
private Map<String,String> map = new HashMap<>();
public RecyAdapter(Context context) {
this.context = context;
}
/**
* 新增資料並更新顯示
* */
public void add(CartBean cartBean){
//傳進來的是bean物件
if(list == null){
list = new ArrayList<>();
}
//第一層遍歷商家和商品
for (CartBean.DataBean shop : cartBean.getData()){
//把商品的id和商品的名稱新增到map集合裡 ,,為了之後方便呼叫
map.put(shop.getSellerid(),shop.getSellerName());
//第二層遍歷裡面的商品
for (int i=0;i<shop.getList().size();i++){
//新增到list集合裡
list.add(shop.getList().get(i));
}
}
//呼叫方法 設定顯示或隱藏 商鋪名
setFirst(list);
notifyDataSetChanged();
}
/**
* 設定資料來源,控制是否顯示商家
* */
private void setFirst(List<CartBean.DataBean.ListBean> list) {
if(list.size()>0){
//如果是第一條資料就設定isFirst為1
list.get(0).setIsFirst(1);
//從第二條開始遍歷
for (int i=1;i<list.size();i++){
//如果和前一個商品是同一家商店的
if (list.get(i).getSellerid() == list.get(i-1).getSellerid()){
//設定成2不顯示商鋪
list.get(i).setIsFirst(2);
}else{//設定成1顯示商鋪
list.get(i).setIsFirst(1);
//如果當前條目選中,把當前的商鋪也選中
if (list.get(i).isItem_check()==true){
list.get(i).setShop_check(list.get(i).isItem_check());
}
}
}
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context, R.layout.recy_cart_item,null);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
/**
* 設定商鋪的 shop_checkbox和商鋪的名字 顯示或隱藏
* */
if(list.get(position).getIsFirst()==1){
//顯示商家
holder.shop_checkbox.setVisibility(View.VISIBLE);
holder.shop_name.setVisibility(View.VISIBLE);
//設定shop_checkbox的選中狀態
holder.shop_checkbox.setChecked(list.get(position).isShop_check());
holder.shop_name.setText(map.get(String.valueOf(list.get(position).getSellerid())));
}else{//2
//隱藏商家
holder.shop_name.setVisibility(View.GONE);
holder.shop_checkbox.setVisibility(View.GONE);
}
//拆分images欄位
String[] split = list.get(position).getImages().split("\\|");
//設定商品的圖片
ImageLoader.getInstance().displayImage(split[0],holder.item_face);
//控制商品的item_checkbox,,根據欄位改變
holder.item_checkbox.setChecked(list.get(position).isItem_check());
holder.item_name.setText(list.get(position).getTitle());
holder.item_price.setText(list.get(position).getPrice()+"");
//呼叫customjiajian裡面的方法設定 加減號中間的數字
holder.customJiaJian.setEditText(list.get(position).getNum());
//商鋪的shop_checkbox點選事件 ,控制商品的item_checkbox
holder.shop_checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//先改變資料來源中的shop_check
list.get(position).setShop_check(holder.shop_checkbox.isChecked());
for (int i=0;i<list.size();i++){
//如果是同一家商鋪的 都給成相同狀態
if(list.get(position).getSellerid()==list.get(i).getSellerid()){
//當前條目的選中狀態 設定成 當前商鋪的選中狀態
list.get(i).setItem_check(holder.shop_checkbox.isChecked());
}
}
//重新整理介面卡
notifyDataSetChanged();
//呼叫求和的方法
sum(list);
}
});
//商品的item_checkbox點選事件,控制商鋪的shop_checkbox
holder.item_checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//先改變資料來源中的item_checkbox
list.get(position).setItem_check(holder.item_checkbox.isChecked());
//反向控制商鋪的shop_checkbox
for (int i=0;i<list.size();i++){
for (int j=0;j<list.size();j++){
//如果兩個商品是同一家店鋪的 並且 這兩個商品的item_checkbox選中狀態不一樣
if(list.get(i).getSellerid()==list.get(j).getSellerid() && !list.get(j).isItem_check()){
//就把商鋪的shop_checkbox改成false
list.get(i).setShop_check(false);
break;
}else{
//同一家商鋪的商品 選中狀態都一樣,就把商鋪shop_checkbox狀態改成true
list.get(i).setShop_check(true);
}
}
}
//更新介面卡
notifyDataSetChanged();
//呼叫求和的方法
sum(list);
}
});
//刪除條目的點選事件
holder.item_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
list.remove(position);//移除集合中的當前資料
//刪除完當前的條目 重新判斷商鋪的顯示隱藏
setFirst(list);
//呼叫重新求和
sum(list);
notifyDataSetChanged();
}
});
//加減號的監聽,
holder.customJiaJian.setCustomListener(new CustomJiaJian.CustomListener() {
@Override
public void jiajian(int count) {
//改變資料來源中的數量
list.get(position).setNum(count);
notifyDataSetChanged();
sum(list);
}
@Override
//輸入值 求總價
public void shuRuZhi(int count) {
list.get(position).setNum(count);
notifyDataSetChanged();
sum(list);
}
});
}
/**
* 計算總價的方法
* */
private void sum(List<CartBean.DataBean.ListBean> list){
int totalNum = 0;//初始的總價為0
float totalMoney = 0.0f;
boolean allCheck = true;
for (int i=0;i<list.size();i++){
//把 已經選中的 條目 計算價格
if (list.get(i).isItem_check()){
totalNum += list.get(i).getNum();
totalMoney += list.get(i).getNum() * list.get(i).getPrice();
}else{
//如果有個未選中,就標記為false
allCheck = false;
}
}
//介面回調出去 把總價 總數量 和allcheck 傳給view層
updateListener.setTotal(totalMoney+"",totalNum+"",allCheck);
}
//view層呼叫這個方法, 點選quanxuan按鈕的操作
public void quanXuan(boolean checked) {
for (int i=0;i<list.size();i++){
list.get(i).setShop_check(checked);
list.get(i).setItem_check(checked);
}
notifyDataSetChanged();
sum(list);
}
@Override
public int getItemCount() {
return list==null?0:list.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private final CheckBox shop_checkbox;
private final TextView shop_name;
private final CheckBox item_checkbox;
private final TextView item_name;
private final TextView item_price;
private final CustomJiaJian customJiaJian;
private final ImageView item_delete;
private final ImageView item_face;
public MyViewHolder(View itemView) {
super(itemView);
shop_checkbox = (CheckBox) itemView.findViewById(R.id.shop_checkbox);
shop_name = (TextView) itemView.findViewById(R.id.shop_name);
item_checkbox = (CheckBox) itemView.findViewById(R.id.item_checkbox);
item_name = (TextView) itemView.findViewById(R.id.item_name);
item_price = (TextView) itemView.findViewById(R.id.item_price);
customJiaJian = (CustomJiaJian) itemView.findViewById(R.id.custom_jiajian);
item_delete = (ImageView) itemView.findViewById(R.id.item_delete);
item_face = (ImageView) itemView.findViewById(R.id.item_face);
}
}
UpdateListener updateListener;
public void setUpdateListener(UpdateListener updateListener){
this.updateListener = updateListener;
}
//介面
public interface UpdateListener{
public void setTotal(String total,String num,boolean allCheck);
}
}
相關推薦
MVP實現二級購物車
效果圖 使用介面:http://120.27.23.105/product/getCarts?uid=100 匯入依賴 compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'com.google.code.g
Android實現帶商家的二級購物車+MVP
MainActivity程式碼 package com.bwie.shopcar.activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import and
mvp實現Xrecyclerview的上下拉和購物車功能(仿餓了麼)
首先先匯入咱們的依賴 implementation 'com.android.support:design:28.0.0' implementation 'com.google.code.gson:gson:2.8.5' implementation 'cn.b
mvp實現Xrecyclerview的上下拉和購物車功能(仿淘寶)
首先先匯入我們要使用的依賴 implementation 'com.android.support:design:28.0.0' implementation 'com.google.code.gson:gson:2.8.5' implementation 'cn.bingoo
貝塞爾曲線實現的購物車添加商品動畫效果
right map 繪制 開始 enter 監聽 idg 過程 protected 效果圖如下: 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xm
用javascript實現的購物車實例
close meta parseint ces post count ret selected html 基於javascript實現的購物車實例: 首先是效果和功能,如下圖所示,具有購物車的基本功能。 包括1、選中和全選商品;2、商品數量的增減;3、單個商品價格的計算;4
js實現仿購物車加減效果
eight pin lis png tofixed solid alt mage align 代碼如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g
ExpandableListView控件實現二級列表
XP 基本 @override 適配 extc height encoding 是否 [] 效果圖如下: 二級列表附有點擊事件。 1、布局文件: 此處加了一個自定義的導航RelativeLayout,記得註activity的時候添加 android:theme="@s
用js和jq分別實現二級聯動效果
js jq 二級聯動界面: 兩個下拉框。用js方法實現:用jq方法實現:註意:在js中的for(var a in 數組) 其中的變量a依舊是下標,不是元素的值,跟其他的語言有點不一樣。同時,在js中,數組的下標是可以存放文字的。用js和jq分別實現二級聯動效果
jQuery實現飛入購物車功能
jQuery要實現的效果:思路:點擊商品,圖片就會飛入購物車,不但變小,而且加入到購物車後消失 了,不但如此,商品的圖片還在,所以我們使用克隆的方法,加入到購物車後清除購物車即可,然後購物車+1首先獲取商品圖片的位置及大小,並放到body上(否則飛入的時候看不到效果),然後獲取購物車的方位,最後使用動畫效果實
【轉】Asp.net 用datalist嵌套的方法實現二級菜單的分類導航
col ESS 方法 tab server select lec cut esp 剛開始學習Asp.net做網站的時候, 做的是一個電子圖書購買網站,發現圖書有多級類目。 例如:小說分類下面世界名著,中國古典小說....... 文學類目下有
SpringBoot+Mybatis+redis實現二級緩存
gap nal configure argument prope gets ssp tro 1.2 對於查詢比較多的項目可以考慮配置二級緩存,mybatis本身的二級緩存是緩存到本地,但是對於多個節點的項目來說,可能會出現數據不一致的問題,所以采用redis緩存,這樣二級緩
jQuery+php實現二級聯動
view fun val -- where his this pre public php代碼: public function liandong(){ $arr = Db::table("city")->where("pid=0")->sel
jQuery實現加入購物車飛入動畫效果之開發不停,填坑不止(起點位置在Y軸方向位置偏移)
開發時為了完成購物車的飛入拋物線,因為懶惰隨大流使用了fly.js外掛,用的時候遇到的兩個坑坑~~ 1. 有滾動條時,拋物體的起點位置在Y軸方向上有位置偏移,偏大 2. 頁面有滾動條時,拋物體的結束位置不一樣,偏大 我:(⊙o⊙)…煩煩的。。。這就是用別人東西的代價 。。。。。。 不
純css實現二級導航
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>企業搜尋頁面</title> <style>
jquery+ajax實現二級聯動
實現效果圖: 前臺頁面: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jquery+ajax實現二級聯動</title>
簡單的二級購物車(2)
6.自定義的包 6.1 —CarTitleView public class CarTitleView extends LinearLayout implements View.OnClickListener{ private CarTitleInterface carT
簡單的二級購物車
1.許可權 依賴 <uses-permission android:name="android.permission.INTERNET"></uses-permission> compile 'com.squareup.okhttp3:okhttp:3.
用Java Map相關知識實現簡易購物車功能
實現購物車功能 問題:實現一個購物車功能 分析:要實現這個功能,可以建立三個類,分別是Product商品類,ShopCart購物車類,Exercise測試類。Product類,裡面描述商品的一些基本屬性,編號,名稱,單價。 下面演示如何用程式碼實現需求。先定義一個商品類。 package
MVP實現登入記住密碼
佈局,主要有輸入賬號和密碼的輸入框以及記住密碼的複選框,和點選登入的按鈕即可 <?xml version="1.0" encoding="utf-8"?> 接下來用MVP實現主要功能了 view層 public interface Log