Skip to content

Number Counter

DV Infosys edited this page Jul 16, 2019 · 1 revision

NumberCounter

An amazingly simple and easy-to-use library for your counter (or number picker) needs! It started as a Ctrl-C, Ctrl-V code between my projects and now I've decided to make it into a open-source library!

Usage

  • In XML layout:
<com.dvinfosys.widgets.NumberCounter.Counter
            android:id="@+id/number_counter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="8dp"
            app:displayAsInteger="true"
            app:initialValue="16"
            app:maxValue="100"
            app:minValue="1"
            app:minusButtonColor="#D50000"
            app:plusButtonColor="#4CAF50"
            app:stepValue="1"
            app:textColor="@color/color_blue"
            app:textSize="12dp" />
  • In Java:
// Params customization:
counter.setStepValue(0.01);
counter.setMaxValue(100.0);
counter.setMinValue(-100.0);
counter.setCurrentValue(1.0);

// If you want to display as integer just do this:
// counter.setDisplayingInteger(true)

// View customization:
counter.setTextColor(Color.parseColor("#4CAF50"));
counter.setMinusIcon(getDrawable(R.drawable.ic_minus));
counter.setMinusButtonColor(Color.parseColor("#909090"));
counter.setPlusIcon(getDrawable(R.drawable.ic_plus));
counter.setPlusButtonColor(Color.parseColor("#909090"));
counter.setTextSize(16);

// Custom action on release:
counter.setOnReleaseListener(() -> {
    Toast.makeText(this, "Value updated to: " + counter.getCurrentValue(), Toast.LENGTH_SHORT).show();
});
Clone this wiki locally