精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
實現美團、餓了么購物車效果,并本地存儲相關數據
2015-12-23 19:55 1929人閱讀 評論(17) 收藏 舉報
分類:

版權聲明:轉載請標明轉載地址!

目錄(?)[+]

前言

圣誕節快到了,在這里先祝大家圣誕節快樂!


這篇文章就當我送給大家的節日禮物了(可能寫的博客技術含量不是很高或者有些許錯誤,希望大家諒解)。

效果圖

分析

有很多時候我們會得到各式各樣的效果和功能,在了解了任務之后我不建議大家馬上去百度或者編寫代碼。應該先分析任務的邏輯,并思考每部分利用什么控件或者技術實現,哪種實現效果能使我們的邏輯更清晰,即使代碼編寫錯誤當我們修改的時候也不需要改動太大或者重新進行編寫(遵循開閉原則),避免浪費我們的時間。其實就是我們面向接口編程的思想,先抽象后實現。

  1. 對于左側菜單和右側內容部分聯動的效果——采用兩個RecyclerView控件
  2. 添加購物車動畫的實現——采用TranslateAnimation動畫
  3. 數據的存儲、獲取以及刪除——采用xutils框架

是不是感覺簡單分析之后,思路清晰多了,實現起來也知道該從哪里入手了。

代碼實現

1. RecyclerView控件實現左側菜單和右側內容聯動效果

activity_main.xml

<LinearLayout    android:layout_below="@+id/include"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:layout_above="@+id/view"    android:orientation="horizontal">    <android.support.v7.widget.RecyclerView        android:id="@+id/m_list_menu"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="5"        android:scrollbars="none">    </android.support.v7.widget.RecyclerView>    <android.support.v7.widget.RecyclerView        android:id="@+id/m_list_content"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_weight="2"        android:scrollbars="none">    </android.support.v7.widget.RecyclerView></LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

主布局相對來說簡單多了,就不進行詳細的講解了。

item_menu.xml

<LinearLayout    android:id="@+id/black_lay"    android:layout_width="match_parent"    android:layout_height="50dp"    android:gravity="center"    android:orientation="horizontal">    <View        android:id="@+id/item_menu_view_red"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:visibility="gone"        android:layout_weight="30"        android:background="@color/title_color_ff0000"/>    <TextView        android:id="@+id/item_menu_text"        android:layout_width="match_parent"        android:gravity="center_horizontal"        android:layout_height="wrap_content"        android:layout_weight="0.5"        android:textSize="16sp"        android:textColor="@android:color/black"        android:text="好評榜"/>    <View        android:id="@+id/item_menu_view_v"        android:layout_width="0.1dp"        android:layout_height="50dp"        android:background="@color/color_menu_lines"/></LinearLayout>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

菜單布局左右兩側分別有一條豎著的黑線和紅線,當我們進行點擊item操作的時候,需要進行的隱藏和顯示效果來達到該item處于選中狀態。

item_menu_content.xml

item_menu_content就是一個簡單的布局,由于代碼量太大就不進行展示了,大家可以下載我的Demo進行查看。
  • 1
  • 1

RecyclerViewMenuAdapter.java

左側菜單的數據填充器,主要的部分就是在onBindViewHolder方法里面,先讓所有的item顯示為默認狀態,在根據點擊item對應的position來改變該item的狀態即可:

//綁定ViewHolder@Overridepublic void onBindViewHolder(final ViewHolder holder, final int position) {    holder.mTextView.setText(DemoData.ListMenu_STYLE[position]);    //設置所有的item顯示為默認狀態    holder.mLinearLayout.setBackgroundResource(R.color.color_menu_back);    holder.viewRed.setVisibility(View.GONE);    holder.viewV.setVisibility(View.VISIBLE);    //根據點擊item對應的position來改變該item的狀態    if (holder.getPosition() == MainActivity.SELECTPOSITION) {        holder.mLinearLayout.setBackgroundResource(R.color.white);        holder.viewRed.setVisibility(View.VISIBLE);        holder.viewV.setVisibility(View.GONE);    }    setOnListtener(holder);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

RecyclerViewContentAdapter.java

左側內容填充器則為普通的內容沒有什么特殊的地方
  • 1
  • 1

MainActivity.java

/** * 菜單列表    數據填充 */private void setMenuCommonadapter() {     mRecyclerViewMenuCommonadapter = new RecyclerViewMenuAdapter(mContext, stringMenuList);     mRecyclerMenu.setAdapter(mRecyclerViewMenuCommonadapter);     mRecyclerViewMenuCommonadapter.setOnItemClickListener(new RecyclerViewMenuAdapter.OnItemClickListener() {         @Override         public void onItemClick(View v, int position) {             SELECTPOSITION = position;             Log.e("TAG", "SELECTPOSITION:" + SELECTPOSITION);             mRecyclerViewMenuCommonadapter.notifyDataSetChanged();             mRecyclerViewContentCommonadapter.notifyDataSetChanged();         }         @Override         public void onItemLongClick(View v, int position) {}     });}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

當點擊item的時候,改變SELECTPOSITION 的值,再刷新兩個recyclerview即可。

效果圖如下:

由于數據全部都是一樣的所以可能看起來,左側內容部分沒有什么改變,但其實數據已經刷新了。
模擬器和錄制gif圖工具有些問題,所以分割線顯示不全并且有色差,大家如果有什么好的工具可以給我推薦推薦,在這里謝謝大家了!

2.添加購物車動畫的實現

在做添加購物車動畫的時候,首先想到的就是translateanimation平移動畫,公司同事做過類似的動畫所以拿過來稍加修改并封裝成了工具類,使用起來杠杠滴。

/** 動畫 */GoodsAnimUtil.setAnim(MainActivity.this, holder.mImgJia, mCarLay);GoodsAnimUtil.setOnEndAnimListener(new onEndAnim());
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

首先調用工具類里面的setAnim()方法,就可以設置和開始動畫了;
再監聽動畫,當動畫結束時進行相關操作即可。

public static void setAnim(Activity activity , View imgphoto, View imgcar){     mActivity = activity;     mImgcar = imgcar;     // 一個整型數組,用來存儲按鈕的在屏幕的X、Y坐標     int[] start_location = new int[2];     // 這是獲取購買按鈕的在屏幕的X、Y坐標(這也是動畫開始的坐標)     imgphoto.getLocationInWindow(start_location);     int[] start_location1 = new int[]{start_location[0], start_location[1]};     // buyImg是動畫的圖片,我的是一個小球(R.drawable.sign)     ImageView buyImg = new ImageView(mActivity);     // 設置buyImg的圖片     buyImg.setImageResource(R.mipmap.aii);     // 開始執行動畫     startAnim(buyImg, start_location1);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • imgphoto代表我們點擊的view,通過imgphoto.getLocationInWindow(start_location)得帶我們點擊view的橫坐標和縱坐標,并存在start_location數組里面;
  • imgcar代表結束位置的view,也是通過mImgcar.getLocationInWindow(end_location)得到結束位置的橫坐標和縱坐標,并存在end_location數組里面。
/** *開始動畫 */private static void startAnim(final View v, int[] start_location) {    anim_mask_layout = null;    anim_mask_layout = createAnimLayout();    anim_mask_layout.addView(v);//把動畫小球添加到動畫層    view = addViewToAnimLayout(anim_mask_layout, v,start_location);    int[] end_location = new int[2];// 這是用來存儲動畫結束位置的X、Y坐標    mImgcar.getLocationInWindow(end_location);// shopCart是那個購物車    int width = getWindowsWidth(mActivity);    // 計算位移    int endY = end_location[1] - start_location[1];// 動畫位移的y坐標    int endX = 0 - start_location[0] + (mImgcar.getWidth() / 2);// 動畫位移的X坐標    TranslateAnimation translateAnimationX = new TranslateAnimation(0,endX, 0, 0);    translateAnimationX.setInterpolator(new LinearInterpolator());    translateAnimationX.setRepeatCount(0);// 動畫重復執行的次數    translateAnimationX.setFillAfter(true);    TranslateAnimation translateAnimationY = new TranslateAnimation(0, 0,0, endY);    translateAnimationY.setInterpolator(new AccelerateInterpolator());    translateAnimationY.setRepeatCount(0);// 動畫重復執行的次數    translateAnimationX.setFillAfter(true);    ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.3f, 1.0f, 0.3f);    scaleAnimation.setInterpolator(new AccelerateInterpolator());    scaleAnimation.setRepeatCount(0);// 動畫重復執行的次數    scaleAnimation.setFillAfter(true);    scaleAnimation.setDuration(300);    final AnimationSet set = new AnimationSet(false);    set.setFillAfter(false);    set.addAnimation(translateAnimationY);    set.addAnimation(translateAnimationX);    //set.setStartOffset(300);    set.setDuration(800);// 動畫的執行時間    view.startAnimation(set);    // 動畫監聽事件    set.setAnimationListener(new Animation.AnimationListener() {        // 動畫的開始        @Override        public void onAnimationStart(Animation animation) {            v.setVisibility(View.VISIBLE);        }        @Override        public void onAnimationRepeat(Animation animation) {}        // 動畫的結束        @Override        public void onAnimationEnd(Animation animation) {            v.setVisibility(View.GONE);            anim_mask_layout.removeAllViews();            YoYo.with(Techniques.Bounce).withListener(new Animator.AnimatorListener() {                @Override                public void onAnimationStart(Animator animation) {}                @Override                public void onAnimationEnd(Animator animation) {                    mEndAnimListener.onEndAnim();                }                @Override                public void onAnimationCancel(Animator animation) {}                @Override                public void onAnimationRepeat(Animator animation) {}            }).interpolate(new BounceInterpolator()).duration(400).playOn(mImgcar);        }    });}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

在這堆復雜的代碼中,我們只需要關心這兩句代碼即可:

// 計算位移int endY = end_location[1] - start_location[1];// 動畫位移的y坐標int endX = end_location[0] - start_location[0] + (mImgcar.getWidth() / 2);// 動畫位移的X坐標
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

在我們的手機界面里,左上角為(0,0),所以從上向下是正,從左向右是正,所以:
結束位置的縱坐標減去開始位置的縱坐標作為動畫位移的y距離;
結束位置的橫坐標減去開始位置的橫坐標再加上結束位置的view的一半作為動畫移動的x距離。

動畫效果就實現了,當然如果你想實現其他效果只需要修改GoodsAnimUtil類即可,而主代碼中的代碼不需要改變,這就體現出了低耦合的重要性;

3.采用xutils框架實現本地數據庫

GoodsBean .java

@Table(name = "goods")public class GoodsBean extends GoodsBase{    @Column(column = "menupos")    private int menupos;    @Column(column = "goodsid")    private int goodsid;    @Column(column = "goodsnum")    private String goodsnum;    @Column(column = "goodsprice")    private String goodsprice;    public int getMenupos() {        return menupos;    }    public void setMenupos(int menupos) {        this.menupos = menupos;    }    public int getGoodsid() {        return goodsid;    }    public void setGoodsid(int goodsid) {        this.goodsid = goodsid;    }    public String getGoodsnum() {        return goodsnum;    }    public void setGoodsnum(String goodsnum) {        this.goodsnum = goodsnum;    }    public String getGoodsprice() {        return goodsprice;    }    public void setGoodsprice(String goodsprice) {        this.goodsprice = goodsprice;    }    @Override    public String toString() {        return "GoodsBean{" +                "menupos='" + menupos + '\'' +                ", goodsid='" + goodsid + '\'' +                ", goodsnum='" + goodsnum + '\'' +                ", goodsprice='" + goodsprice + '\'' +                '}';    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

新建數據庫goods,菜單欄每項對應的menupos、商品的goodsid、存儲數量goodsnum和每個商品對應的價格goodsprice這幾個字段是我們在進行數據庫操作的時候需要使用到的字段;

分析效果圖:

a.點擊加號,根據菜單欄的menupos和對應的商品的goodsid進行存儲數據;
b.點擊減號,根據菜單欄的menupos和對應的商品的goodsid進行存儲數據;
c.點擊菜單欄的item,根據菜單欄的menupos得到二級每個商品已經存儲的數量;
d.點擊菜單欄的item,根據菜單欄的menupos得到二級所有商品的存儲數量;
e.點擊菜單欄的item,根據菜單欄的menupos得到二級所有商品的存儲價格;
f.刪除所有的存儲數據。

根據分析結果,編寫接口以及我們需要實現的方法:

GoodsDataBaseInterface .java

public interface GoodsDataBaseInterface {    /** 添加和刪除購物的數量 */    int saveGoodsNumber(Context context, int menupos, int goodsid, String goodsnum, String goodsprice);    /** 根據下標得到 第二級對應購物的數量 */    int getSecondGoodsNumber(Context context, int menupos, int goodsid);    /** 根據第一級的下標 得到第二級的所有購物數量 */    int getSecondGoodsNumberAll(Context context, int menupos);    /** 根據第一級的下標 得到第二級的所有購物的價格 */    int getSecondGoodsPriceAll(Context context, int menupos);    /** 刪除所有的購物數據 */    void deleteAll(Context context);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

編寫實現類OperateGoodsDataBase繼承GoodsDataBaseInterface 接口:

public class OperateGoodsDataBase implements GoodsDataBaseInterface{   private static OperateGoodsDataBase instance  = new OperateGoodsDataBase();   public static OperateGoodsDataBase getInstance(){       return  instance;   }   private OperateGoodsDataBase(){}   /**    *添加和刪除商品數量,并得到商品數量    */   @Override   public int saveGoodsNumber(Context context, int menupos, int goodsid, String goodsnum , String goodsprice) {       return OperateGoodsDataBaseStatic.saveGoodsNumber(context , menupos , goodsid , goodsnum ,goodsprice);   }   /**    *根據下標得到 第二級對應購物的數量    */   @Override   public int getSecondGoodsNumber(Context context, int menupos, int goodsid) {       return OperateGoodsDataBaseStatic.getSecondGoodsNumber(context, menupos, goodsid);   }   /**    * 根據第一級的下標 得到第二級的所有購物數量    */   @Override   public int getSecondGoodsNumberAll(Context context, int menupos) {       return OperateGoodsDataBaseStatic.getSecondGoodsNumberAll(context, menupos);   }   /**    *據第一級的下標 得到第二級的所有購物的價格    */   @Override   public int getSecondGoodsPriceAll(Context context, int menupos) {       return OperateGoodsDataBaseStatic.getSecondGoodsPriceAll(context, menupos);   }   /**    *刪除所有的購物數據    */   @Override   public void deleteAll(Context context) {       OperateGoodsDataBaseStatic.deleteAll(context);   }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

在實現類里面寫了一個單例,這樣在其他類里面調用該單例只會有一個實現類,減少了內存的消耗;

OperateGoodsDataBaseStatic.java

public class OperateGoodsDataBaseStatic{    /**     *添加和刪除商品數量     */    public static int saveGoodsNumber(Context context, int menupos, int goodsid, String goodsnum , String goodsprice) {        DbUtils utils = DbUtils.create(context);        GoodsBean goodsBean = null;        goodsBean =new GoodsBean();        goodsBean.setMenupos(menupos);        goodsBean.setGoodsid(goodsid);        goodsBean.setGoodsnum(goodsnum);        goodsBean.setGoodsprice(goodsprice);        try {            GoodsBean bean = utils.findFirst(Selector.from(GoodsBean.class).where("menupos" , "=" , menupos).and("goodsid", "=", goodsid));            //如果有這條數據,數量直接加1;否則就插入表里面            if(bean == null){                Log.e("TAG", "還沒有該商品");                utils.save(goodsBean);                Log.e("TAG" , "該商品已經存儲");                return getSecondGoodsNumber(context , menupos , goodsid);            }else{                Log.e("TAG" , "已經有該商品");                //返回添加商品之后的商品總數                return updateNum(context, menupos, goodsid, goodsnum);            }        } catch (DbException e) {            e.printStackTrace();        }        Log.e("TAG" , "添加商品失敗");        utils.close();        return 0;    }    /**修改數量,直接傳入數量**/    public static int updateNum(Context context , int menupos , int goodsid , String goodsnum){        DbUtils utils = DbUtils.create(context);        try {            GoodsBean bean = utils.findFirst(Selector.from(GoodsBean.class).where("menupos", "=", menupos).and("goodsid", "=", goodsid));            bean.setGoodsnum(goodsnum);            utils.update(bean);            Log.e("TAG", "該商品數量改變為:" + getSecondGoodsNumber(context, menupos, goodsid));            return getSecondGoodsNumber(context , menupos , goodsid);        } catch (DbException e) {            e.printStackTrace();        }        utils.close();        return 0;    }    /**     *根據下標得到 第二級對應購物的數量     */    public static int getSecondGoodsNumber(Context context , int menupos , int goodsid) {        DbUtils utils = DbUtils.create(context);        if(utils == null){            Log.e("TAG" , "還沒有該數據庫");            return 0;        }        try {            GoodsBean bean = utils.findFirst(Selector.from(GoodsBean.class).where("menupos", "=", menupos).and("goodsid", "=", goodsid));            if(bean == null){                Log.e("TAG" , "還沒有該存儲商品");                return 0;            }else{                Log.e("TAG" , "獲取商品數量成功:" + Integer.parseInt(bean.getGoodsnum()));                return Integer.parseInt(bean.getGoodsnum());            }        } catch (DbException e) {            e.printStackTrace();        }        utils.close();        Log.e("TAG", "獲取商品數量失敗");        return 0;    }    /**     * 根據第一級的下標 得到第二級的所有購物數量     */    public static int getSecondGoodsNumberAll(Context context, int menupos) {        DbUtils utils = DbUtils.create(context);        int mSecondGoodsNum = 0;        ArrayList<GoodsBean> mGoodsBeanList = null;        mGoodsBeanList = getSecondGoodsTypeList(context);        if(mGoodsBeanList == null){            Log.e("TAG" , "獲取商品類型總數失敗");            return 0;        }        for(int i = 0 ; i < mGoodsBeanList.size() ; i++){            if(mGoodsBeanList.get(i).getMenupos() == menupos){                mSecondGoodsNum += Integer.parseInt(mGoodsBeanList.get(i).getGoodsnum());            }        }        Log.e("TAG", "根據第一級的下標 得到第二級的所有購物數量成功:" + mSecondGoodsNum);        utils.close();        return mSecondGoodsNum;    }    /**     *根據第一級的下標 得到第二級商品所有商品類型集合     */    public static ArrayList<GoodsBean> getSecondGoodsTypeList(Context context){        DbUtils utils = DbUtils.create(context);        ArrayList<GoodsBean> list = null;        try {            list = (ArrayList<GoodsBean>) DbUtils.create(context).findAll(GoodsBean.class);            if(list == null){                Log.e("TAG" , "該二級商品還沒有存儲數據");                return null;            }else{                Log.e("TAG" , "根據第一級的下標 得到第二級商品類型總數成功:" + list.size());                return list;            }        } catch (DbException e) {            e.printStackTrace();        }        Log.e("TAG" , "根據第一級的下標 得到第二級商品類型總數失敗");        return null;    }    /**     *據第一級的下標 得到第二級的所有購物的價格     */    public static int getSecondGoodsPriceAll(Context context, int menupos) {        DbUtils utils = DbUtils.create(context);        int mSecondGoodsPrice = 0;        ArrayList<GoodsBean> mGoodsBeanList = null;        mGoodsBeanList = getSecondGoodsTypeList(context);        if(mGoodsBeanList == null){            Log.e("TAG" , "獲取商品類型總數失敗");            return 0;        }        for(int i = 0 ; i < mGoodsBeanList.size(); i++){            if(mGoodsBeanList.get(i).getMenupos() == menupos){                mSecondGoodsPrice += Integer.parseInt(mGoodsBeanList.get(i).getGoodsnum()) * Integer.parseInt(mGoodsBeanList.get(i).getGoodsprice());            }        }        Log.e("TAG" , "根據第一級的下標 得到第二級的所有購物的價格成功:" + mSecondGoodsPrice);        utils.close();        Log.e("TAG" , "根據第一級的下標 得到第二級的所有購物的價格失敗");        return mSecondGoodsPrice;    }    /**     *刪除所有的購物數據     */    public static void deleteAll(Context context) {        DbUtils utils = DbUtils.create(context);        try {            List<GoodsBean> records = utils.findAll(GoodsBean.class);            utils.deleteAll(records);        } catch (DbException e) {            e.printStackTrace();        }        utils.close();    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151

對于數據庫的操作,沒有什么復雜的邏輯,只需要記住基本的代碼就可以了,所以就不進行講解了,里面備注寫的也十分詳細;

整合代碼

RecyclerViewContentAdapter.java

a.在onBindViewHolder()方法里面根據點擊的一級菜單的position和商品id,判斷數據庫里面是否有該商品,有該商品則顯示減號圖標和對應的存儲數量;

//綁定ViewHolder@Overridepublic void onBindViewHolder(final ViewHolder holder, final int position) {    holder.mImageView.setImageResource(DemoData.ListMenu_PIMAGES[position]);    holder.mTitle.setText(DemoData.ListMenu_PTITLE[position]);    holder.mYueSale.setText("月售" + DemoData.ListMenu_NUMBER[position]);    holder.mPrice.setText(DemoData.ListMenu_PPRICE[position]);    holder.mRatingBar.setRating(Float.parseFloat(DemoData.ListMenu_STAR[position]));    holder.mRatingBar.getRating();    /** 獲取存儲的商品數量 */    if (mGoodsDataBaseInterface.getSecondGoodsNumber(mContext, MainActivity.SELECTPOSITION , DemoData.ListMenu_GOODSID[holder.getPosition()]) == 0) {        holder.mNumber.setText("");        holder.mNumber.setVisibility(View.GONE);        holder.mImgJian.setVisibility(View.GONE);    } else {        holder.mNumber.setText("" + mGoodsDataBaseInterface.getSecondGoodsNumber(mContext, MainActivity.SELECTPOSITION , DemoData.ListMenu_GOODSID[holder.getPosition()]));        holder.mNumber.setVisibility(View.VISIBLE);        holder.mImgJian.setVisibility(View.VISIBLE);    }    setOnListtener(holder);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

b.自定義item點擊、長點擊、添加商品和減少商品的監聽事件;

//觸發protected void setOnListtener(final ViewHolder holder){   if(mOnItemClickListener != null){       holder.itemView.setOnClickListener(new View.OnClickListener() {           @Override           public void onClick(View v) {               mOnItemClickListener.onItemClick(holder);           }       });       holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {           @Override           public boolean onLongClick(View v) {               mOnItemClickListener.onItemLongClick(holder);               return true;           }       });       holder.mImgJia.setOnClickListener(new View.OnClickListener() {           @Override           public void onClick(View v) {               mOnItemClickListener.onItemJiaClick(holder);           }       });       holder.mImgJian.setOnClickListener(new View.OnClickListener() {           @Override           public void onClick(View v) {               mOnItemClickListener.onItemJianClick(holder);           }       });   }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

c.點擊加號和減號的時候,進行相關的操作;

MainActivity.java

mRecyclerViewContentCommonadapter.setOnItemClickListener(new RecyclerViewContentAdapter.OnItemClickListener() {@Overridepublic void onItemClick(RecyclerViewContentAdapter.ViewHolder holder) {}@Overridepublic void onItemLongClick(RecyclerViewContentAdapter.ViewHolder holder) {}/** 添加 */@Overridepublic void onItemJiaClick(RecyclerViewContentAdapter.ViewHolder holder) {    String numText = holder.mNumber.getText().toString().trim();    /** 點擊加號之前還沒有數據的時候 */    if (numText.isEmpty() || numText.equals("0")) {        Log.e("TAG", "點擊獲取信息:SELECTPOSITION--" + SELECTPOSITION + "  DemoData.ListMenu_GOODSID[position]--" + DemoData.ListMenu_GOODSID[holder.getPosition()]);        holder.mImgJian.setVisibility(View.VISIBLE);        holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], "1", DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");        holder.mNumber.setVisibility(View.VISIBLE);    }/** 點擊加號之前有數據的時候 */    else {        holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], String.valueOf(Integer.parseInt(numText) + 1), DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");    }    /** 動畫 */    GoodsAnimUtil.setAnim(MainActivity.this, holder.mImgJia, mCarLay);    GoodsAnimUtil.setOnEndAnimListener(new onEndAnim());    /** 統計購物總數和購物總價 */}/** 減少 */@Overridepublic void onItemJianClick(RecyclerViewContentAdapter.ViewHolder holder) {    String numText = holder.mNumber.getText().toString().trim();    holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], String.valueOf(Integer.parseInt(numText) - 1), DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");    numText = holder.mNumber.getText().toString().trim();    /** 減完之后  數據為0 */    if (numText.equals("0")) {        holder.mNumber.setVisibility(View.GONE);        holder.mImgJian.setVisibility(View.GONE);    }    setAll();}});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

d.在點擊item的點擊事件、點擊加號監聽動畫結束和點擊減號的時候都要調用setAll()方法進行商品總數和商品價格的數據更新;

/** * 點擊加號和減號的時候設置總數和總價格 */private void setAll() { //設置所有購物數量 if (mGoodsDataBaseInterface.getSecondGoodsNumberAll(mContext, SELECTPOSITION) == 0) {     mListAllNum.setVisibility(View.GONE);     mListAllPrice.setText("¥0");     mListAllNum.setText("0"); } else {     mListAllPrice.setText("¥" + mGoodsDataBaseInterface.getSecondGoodsPriceAll(mContext, SELECTPOSITION) + "");     mListAllNum.setText(mGoodsDataBaseInterface.getSecondGoodsNumberAll(mContext, SELECTPOSITION) + "");     mListAllNum.setVisibility(View.VISIBLE); }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

全部主代碼 MainActivity.java

public class MainActivity extends BaseActivity {    /**     * 標題     */    @InjectView(R.id.m_fml_title_tv)    TextView mTitle;    /**     * 側邊欄菜單RecyclerView     */    @InjectView(R.id.m_list_menu)    RecyclerView mRecyclerMenu;    /**     * 內容RecyclerView     */    @InjectView(R.id.m_list_content)    RecyclerView mRecyclerContent;    /**     * 商品總價     */    @InjectView(R.id.m_list_all_price)    TextView mListAllPrice;    /**     * 物品總數量     */    @InjectView(R.id.m_list_num)    TextView mListAllNum;    /**     * 側邊欄菜單數據填充器     */    private RecyclerViewMenuAdapter mRecyclerViewMenuCommonadapter = null;    /**     * 內容數據填充器     */    private RecyclerViewContentAdapter mRecyclerViewContentCommonadapter = null;    private Context mContext;    /**     * 存儲數據list     */    private List<String> stringMenuList = new ArrayList<String>();    private List<String> stringContentList = new ArrayList<String>();    public static int SELECTPOSITION = 0;    /**     * 數據操作接口     */    GoodsDataBaseInterface mGoodsDataBaseInterface = null;    /**     * 購物車布局     */    @InjectView(R.id.m_list_car_lay)    RelativeLayout mCarLay;    @Override    protected void onCreate(Bundle arg0) {        super.onCreate(arg0);        setContentView(R.layout.activity_main);        ButterKnife.inject(MainActivity.this);        mContext = this;        initView();        setRecyclerView();        initHttp();    }    private void initView() {        mGoodsDataBaseInterface = OperateGoodsDataBase.getInstance();        //清空數據庫緩存        mGoodsDataBaseInterface.deleteAll(mContext);        mTitle.setText("列表菜單");    }    /**     * 模擬網絡請求數據     */    private void initHttp() {        for (int i = 0; i < 10; i++) {            stringMenuList.add("1111");        }        for (int i = 0; i < 4; i++) {            stringContentList.add("2222");        }        setMenuCommonadapter();        setContentCommonadapter();    }    @OnClick({R.id.m_fml_title_back, R.id.m_list_submit})    void onClick(View v) {        switch (v.getId()) {            case R.id.m_fml_title_back:                finish();                break;            case R.id.m_list_submit:                Toast.makeText(mContext, "提交", Toast.LENGTH_SHORT).show();                break;            default:                break;        }    }    /**     * 設置RecyclerView的布局方式     */    private void setRecyclerView() {        //垂直listview顯示方式        mRecyclerMenu.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));        mRecyclerMenu.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.VERTICAL));        mRecyclerContent.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));    }    /**     * 菜單列表    數據填充     */    private void setMenuCommonadapter() {        mRecyclerViewMenuCommonadapter = new RecyclerViewMenuAdapter(mContext, stringMenuList);        mRecyclerMenu.setAdapter(mRecyclerViewMenuCommonadapter);        mRecyclerViewMenuCommonadapter.setOnItemClickListener(new RecyclerViewMenuAdapter.OnItemClickListener() {            @Override            public void onItemClick(View v, int position) {                SELECTPOSITION = position;                Log.e("TAG", "SELECTPOSITION:" + SELECTPOSITION);                mRecyclerViewMenuCommonadapter.notifyDataSetChanged();                mRecyclerViewContentCommonadapter.notifyDataSetChanged();                setAll();            }            @Override            public void onItemLongClick(View v, int position) {}        });    }    /**     * 商品種類列表    數據填充     */    private void setContentCommonadapter() {        mRecyclerViewContentCommonadapter = new RecyclerViewContentAdapter(mContext, stringContentList);        mRecyclerContent.setAdapter(mRecyclerViewContentCommonadapter);        mRecyclerViewContentCommonadapter.setOnItemClickListener(new RecyclerViewContentAdapter.OnItemClickListener() {            @Override            public void onItemClick(RecyclerViewContentAdapter.ViewHolder holder) {}            @Override            public void onItemLongClick(RecyclerViewContentAdapter.ViewHolder holder) {}            /** 添加 */            @Override            public void onItemJiaClick(RecyclerViewContentAdapter.ViewHolder holder) {                String numText = holder.mNumber.getText().toString().trim();                /** 點擊加號之前還沒有數據的時候 */                if (numText.isEmpty() || numText.equals("0")) {                    Log.e("TAG", "點擊獲取信息:SELECTPOSITION--" + SELECTPOSITION + "  DemoData.ListMenu_GOODSID[position]--" + DemoData.ListMenu_GOODSID[holder.getPosition()]);                    holder.mImgJian.setVisibility(View.VISIBLE);                    holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], "1", DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");                    holder.mNumber.setVisibility(View.VISIBLE);                }/** 點擊加號之前有數據的時候 */                else {                    holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], String.valueOf(Integer.parseInt(numText) + 1), DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");                }                /** 動畫 */                GoodsAnimUtil.setAnim(MainActivity.this, holder.mImgJia, mCarLay);                GoodsAnimUtil.setOnEndAnimListener(new onEndAnim());                /** 統計購物總數和購物總價 */            }            /** 減少 */            @Override            public void onItemJianClick(RecyclerViewContentAdapter.ViewHolder holder) {                String numText = holder.mNumber.getText().toString().trim();                holder.mNumber.setText(mGoodsDataBaseInterface.saveGoodsNumber(mContext, SELECTPOSITION, DemoData.ListMenu_GOODSID[holder.getPosition()], String.valueOf(Integer.parseInt(numText) - 1), DemoData.ListMenu_PPRICE[holder.getPosition()]) + "");                numText = holder.mNumber.getText().toString().trim();                /** 減完之后  數據為0 */                if (numText.equals("0")) {                    holder.mNumber.setVisibility(View.GONE);                    holder.mImgJian.setVisibility(View.GONE);                }                setAll();            }        });    }    /**     * 動畫結束后,更新所有數量和所有價格     */    class onEndAnim implements GoodsAnimUtil.OnEndAnimListener {        @Override        public void onEndAnim() {            setAll();        }    }    /**     * 點擊加號和減號的時候設置總數和總價格     */    private void setAll() {        //設置所有購物數量        if (mGoodsDataBaseInterface.getSecondGoodsNumberAll(mContext, SELECTPOSITION) == 0) {            mListAllNum.setVisibility(View.GONE);            mListAllPrice.setText("¥0");            mListAllNum.setText("0");        } else {            mListAllPrice.setText("¥" + mGoodsDataBaseInterface.getSecondGoodsPriceAll(mContext, SELECTPOSITION) + "");            mListAllNum.setText(mGoodsDataBaseInterface.getSecondGoodsNumberAll(mContext, SELECTPOSITION) + "");            mListAllNum.setVisibility(View.VISIBLE);        }    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191

由于牽扯到3個知識點,所以邏輯可能有些亂,所以大家可以查看我編寫的代碼,里面注釋十分詳細,有意見或者疑問的可以共同商討。

源碼下載地址

3
0

我的同類文章

參考知識庫

猜你在找
查看評論
8樓 yedongguan 2016-07-13 15:35發表 [回復]
請問一下,如何從這個Demo中獲取數據傳到下一個界面里面?
Re: Mr豐 2016-07-14 09:12發表 [回復]
回復yedongguan:數據是使用xutils數據庫存儲的,所以在下一個界面從數據庫中取出就可以
7樓 qq_21864809 2016-06-30 14:36發表 [回復]
點快了會從右側上面飄下來
6樓 baidu_35332706 2016-06-20 14:26發表 [回復]
可以把jar包發給我嗎?
Re: Mr豐 2016-06-30 17:53發表 [回復]
回復baidu_35332706:jar包?
5樓 永恒ii 2016-05-06 14:15發表 [回復]
現在用xutils的不多吧??
Re: Mr豐 2016-05-06 15:31發表 [回復]
回復qq_26936889:最近常用的存儲方式是什么,推薦一下吧!
4樓 mennaomiqiaoyi8800 2016-03-24 01:14發表 [回復]
有一個問題,購物車顯示的商品總量和總價只對應一個左側item,切換一個item購物車就重新開始了,不過每個左側item對應的購物車總量和總價互補干擾,求問大神怎么解決?~~希望購物車顯示的是真正的商品總量和總價~~
3樓 mennaomiqiaoyi8800 2016-03-24 01:14發表 [回復]
有一個問題,購物車顯示的商品總量和總價只對應一個左側item,切換一個item購物車就重新開始了,不過每個左側item對應的購物車總量和總價互補干擾,求問大神怎么解決?~~希望購物車顯示的是真正的商品總量和總價~~
2樓 山寨戴王 2015-12-29 10:37發表 [回復]
好東西。慢慢研究。
1樓 lv910822 2015-12-26 15:39發表 [回復]
你好,請問GoodsAnimUtil中的YoYo和Techniques這兩個類是引用的哪個jar包啊
Re: Mr豐 2015-12-26 15:44發表 [回復]
回復lv910822:添加依賴
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
Re: lv910822 2015-12-26 15:46發表 [回復]
你寫的是Maven項目?
Re: Mr豐 2015-12-26 15:48發表 [回復]
回復lv910822:Android項目 使用AndroidStudio開發的。。。。
Re: lv910822 2015-12-26 16:03發表 [回復]
1025202464,這個是我的QQ,求幫助啊,大神
Re: lv910822 2015-12-26 15:50發表 [回復]
我用eclipse開發的,怎么搞阿。。。
Re: Mr豐 2015-12-26 15:57發表 [回復]
回復lv910822:我找了一個,你可以試一下
https://github.com/fengmaolian/Eclipse-AndroidViewAnimations-1.14.3
發表評論
本站僅提供存儲服務,所有內容均由用戶發布,如發現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java實現運用HashMap充當購物車,goodbean充當存放數據
Android游戲開發----動畫SurfaceView詳解
Android
RecyclerView適配器的超省寫法
2.5.0 構建一個可復用的自定義BaseAdapter | 菜鳥教程
memcached java client 源代碼分析
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服

主站蜘蛛池模板: 丽水市| 茶陵县| 绥化市| 贵溪市| 余姚市| 台南县| 柳江县| 台江县| 南汇区| 共和县| 广德县| 花莲市| 武川县| 万荣县| 夏河县| 祁门县| 玉溪市| 综艺| 巩义市| 星座| 克东县| 微博| 营口市| 梁山县| 平泉县| 卢龙县| 安福县| 崇左市| 瑞丽市| 库尔勒市| 兰考县| 平果县| 攀枝花市| 综艺| 中西区| 清水县| 丰镇市| 阳高县| 离岛区| 子长县| 牟定县|