最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 購物車加減功能的實現(xiàn)代碼

 更新時間:2020年04月26日 17:30:54   作者:Mister.張  
這篇文章主要介紹了Android 實現(xiàn)購物車加減功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

Android 實現(xiàn)購物車加減功能,效果圖如下所示:

在這里插入圖片描述

public class adderView extends LinearLayout implements View.OnClickListener, TextWatcher {
 private int amount = 0; //購買數(shù)量
 private int goods_storage = Integer.MAX_VALUE; //商品庫存
 private OnAmountChangeListener mListener;
 private EditText etAmount;
 private Button btnDecrease;
 private Button btnIncrease;
 public adderView(Context context) {
  this(context, null);
 }
 public adderView(Context context, AttributeSet attrs) {
  super(context, attrs);
  LayoutInflater.from(context).inflate(R.layout.number_adder, this);
  etAmount = (EditText) findViewById(R.id.etAmount);
  btnDecrease = (Button) findViewById(R.id.btnDecrease);
  btnIncrease = (Button) findViewById(R.id.btnIncrease);
  btnDecrease.setOnClickListener(this);
  btnIncrease.setOnClickListener(this);
  etAmount.addTextChangedListener(this);
  TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.AmountView);
  int btnWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_btnWidth, 100);
  int tvWidth = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_tvWidth, 200);
  int tvTextSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_tvTextSize, 0);
  int btnTextSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.AmountView_btnTextSize, 0);
  obtainStyledAttributes.recycle();
  LayoutParams btnParams = new LayoutParams(btnWidth, LayoutParams.MATCH_PARENT);
  btnDecrease.setLayoutParams(btnParams);
  btnIncrease.setLayoutParams(btnParams);
  if (btnTextSize != 0) {
   btnDecrease.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnTextSize);
   btnIncrease.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnTextSize);
  }
  LayoutParams textParams = new LayoutParams(tvWidth, LayoutParams.MATCH_PARENT);
  etAmount.setLayoutParams(textParams);
  if (tvTextSize != 0) {
   etAmount.setTextSize(tvTextSize);
  }
 }
 public void setOnAmountChangeListener(OnAmountChangeListener onAmountChangeListener) {
  this.mListener = onAmountChangeListener;
 }
 public void setGoods_storage(int goods_storage) {
  this.goods_storage = goods_storage;
 }
 public void setTextCount(int count){
  this.amount = count;
  this.etAmount.setText(amount+"");
 }
 @Override
 public void onClick(View v) {
  int i = v.getId();
  if (i == R.id.btnDecrease) {
   if (amount > 0) {
    amount--;
    etAmount.setText(amount + "");
   }
  } else if (i == R.id.btnIncrease) {
   if (amount < goods_storage) {
    amount++;
    etAmount.setText(amount + "");
   }
  }
  etAmount.clearFocus();
  if (mListener != null) {
   mListener.onAmountChange(this, amount);
  }
 }
 @Override
 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 }
 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
 }
 @Override
 public void afterTextChanged(Editable s) {
  if (s.toString().isEmpty())
   return;
  amount = Integer.valueOf(s.toString());
  if (amount > goods_storage) {
   etAmount.setText(goods_storage + "");
   return;
  }
  if (amount == 0){
//   btnDecrease.setBackgroundResource(R.drawable.jian);
  }
  if (amount > 0){
//   btnDecrease.setBackgroundResource(R.drawable.lvjian);
  }
  if (mListener != null) {
   mListener.onAmountChange(this, amount);
  }
 }
 public interface OnAmountChangeListener {
  void onAmountChange(View view, int amount);
 }
<?xml version="1.0" encoding="utf-8"?>
<com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="90px"
 android:focusable="true"
 android:divider="@drawable/divder"
 android:background="@drawable/bg_amout_layout"
 android:showDividers="middle"
 android:orientation="horizontal">
 <Button
  android:id="@+id/btnDecrease"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:gravity="center"
  android:background="@drawable/jian"/>
 <EditText
  android:id="@+id/etAmount"
  android:layout_width="200px"
  android:layout_height="match_parent"
  android:minWidth="150px"
  android:layout_weight="2"
  android:background="@null"
  android:inputType="number"
  android:textSize="13sp"
  android:text="0"
  android:gravity="center"/>
 <Button
  android:id="@+id/btnIncrease"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:gravity="center"
  android:background="@drawable/jia"/>
</com.zhy.autolayout.AutoLinearLayout>

到此這篇關(guān)于Android 購物車加減功能的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)android 購物車加減內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android 滑動定位和吸附懸停效果實現(xiàn)代碼

    Android 滑動定位和吸附懸停效果實現(xiàn)代碼

    這篇文章主要介紹了Android 滑動定位和吸附懸停效果實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • Android設(shè)計模式之Builder模式詳解

    Android設(shè)計模式之Builder模式詳解

    這篇文章主要為大家詳細介紹了Android設(shè)計模式之Builder模式,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • RelativeLayout(相對布局)用法實例講解

    RelativeLayout(相對布局)用法實例講解

    在本文里小編給大家分享了關(guān)于RelativeLayout(相對布局)用法知識點以及對應的實例內(nèi)容,需要的朋友們學習下。
    2019-02-02
  • android實現(xiàn)手機截屏并保存截圖功能

    android實現(xiàn)手機截屏并保存截圖功能

    這篇文章主要為大家詳細介紹了android實現(xiàn)手機截屏并保存截圖功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • ViewPager+Fragment實現(xiàn)側(cè)滑導航欄

    ViewPager+Fragment實現(xiàn)側(cè)滑導航欄

    這篇文章主要為大家詳細介紹了ViewPager+Fragment實現(xiàn)側(cè)滑導航欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • 解決android studio中使用monitor工具無法打開data文件夾問題

    解決android studio中使用monitor工具無法打開data文件夾問題

    這篇文章主要介紹了解決android studio中使用monitor工具無法打開data文件夾問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • Android 8.0系統(tǒng)中應用圖標的適配技巧

    Android 8.0系統(tǒng)中應用圖標的適配技巧

    今天小編就為大家分享一篇關(guān)于Android 8.0系統(tǒng)中應用圖標的適配技巧,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Android實現(xiàn)發(fā)送短信功能實例詳解

    Android實現(xiàn)發(fā)送短信功能實例詳解

    這篇文章主要介紹了Android實現(xiàn)發(fā)送短信功能的方法,結(jié)合實例形式較為詳細的分析了Android實現(xiàn)發(fā)送短信的原理、步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2016-02-02
  • Android應用中使用ViewPager實現(xiàn)類似QQ的界面切換效果

    Android應用中使用ViewPager實現(xiàn)類似QQ的界面切換效果

    這篇文章主要介紹了Android應用中使用ViewPager實現(xiàn)類似QQ的界面切換效果的示例,文中的例子重寫了PagerAdapter,并且講解了如何解決Android下ViewPager和PagerAdapter中調(diào)用notifyDataSetChanged失效的問題,需要的朋友可以參考下
    2016-03-03
  • Android中毛玻璃效果的兩種實現(xiàn)代碼

    Android中毛玻璃效果的兩種實現(xiàn)代碼

    這篇文章主要介紹了Android中毛玻璃效果的兩種實現(xiàn)代碼,第一種是使用JAVA算法FastBlur實現(xiàn),第二種是使用Android自帶類RenderScript 實現(xiàn),本文通過實例代碼介紹的非常詳細,需要的朋友參考下吧
    2024-08-08

最新評論

沁源县| 南城县| 故城县| 互助| 博野县| 荔波县| 江陵县| 嘉定区| 乌鲁木齐市| 木兰县| 温泉县| 彭州市| 婺源县| 普格县| 漠河县| 蓝田县| 五大连池市| 志丹县| 昌平区| 衡南县| 启东市| 武平县| 曲靖市| 太保市| 丰县| 潜山县| 郧西县| 泸西县| 宝应县| 定陶县| 内江市| 大姚县| 雅江县| 梁河县| 南部县| 张家界市| 清原| 岢岚县| 洛隆县| 凤翔县| 潼南县|