Giter Club home page Giter Club logo

numberpickerview's Introduction

NumberPickerView


仿商城添加商品数量,数量加减选择器,支持手动输入

功能简介

1. 仿购物车添加删除商品
2. 支持手动输入数量
3. 支持库存数量的最值监听
4. 支持输入框及按钮的样式自定义
5. 支持输入框数字的单独监听

废话不多说,先看效果图

使用方法

project工程目录build.gradle添加依赖

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

app项目的目录build.gradle添加依赖

dependencies {
	        implementation 'com.github.NewHuLe:NumberPickerView:v1.2'
	}

支持的自定义属性

<resources>
    <declare-styleable name="NumberButton">
        <attr name="editable" format="boolean"/>  //输入框是否就可以编辑
        <attr name="buttonWidth" format="dimension" />  // 按钮的宽度
        <attr name="editextWidth" format="dimension" />  // 输入框的宽度
        <attr name="textSize" format="dimension"/>  // 字体大小
        <attr name="textColor" format="color"/>  // 字体颜色
        <attr name="backgroud" format="reference"/>  // 整体框的背景
        <attr name="individer" format="reference"/>  // 内部垂直分割线
        <attr name="addBackground" format="reference"/>  //左边按钮样式
        <attr name="subBackground" format="reference"/>  //右边按钮样式
    </declare-styleable>

Xml定义

     <cn.com.cesgroup.numpickerview.NumberPickerView
        android:id="@+id/purchase_num3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        app:addBackground="@color/colorPrimary"
        app:backgroud="@color/colorAccent"
        app:buttonWidth="40dp"
        app:editable="true"
        app:editextWidth="120dp"
        app:individer="@drawable/divider_horizontal2"
        app:subBackground="@color/colorPrimary"
        app:textColor="@android:color/black"
        app:textSize="14sp" />

使用方法

        NumberPickerView numberPickerView1 = (NumberPickerView) findViewById(R.id.purchase_num1);
        numberPickerView1.setMaxValue(40) //最大输入值,也就是限量,默认无限大
                .setCurrentInventory(150) // 当前的库存
                .setMinDefaultNum(1)  // 最小限定量
                .setCurrentNum(20)  // 当前数量
                .setmOnClickInputListener(new NumberPickerView.OnClickInputListener() {
            @Override
            public void onWarningForInventory(int inventory) {
                Toast.makeText(MainActivity.this,"超过最大库存",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onWarningMinInput(int minValue) {
                Toast.makeText(MainActivity.this,"低于最小设定值",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onWarningMaxInput(int maxValue) {
                Toast.makeText(MainActivity.this,"超过最大限制量",Toast.LENGTH_SHORT).show();
            }
        });
	  // 默认的监听大部分可以满足要求了,如果有需要自己监听输入框的数字变化的话,需要以下监听
        numberPickerView.setOnInputNumberListener(new NumberPickerView.OnInputNumberListener() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                Log.d("MainActivity",editable.toString());
            }
        });

numberpickerview's People

Contributors

newhule avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.