Giter Club home page Giter Club logo

Comments (4)

ShawnLin013 avatar ShawnLin013 commented on May 26, 2024

Hi @kris-sum,
Sorry for the late reply.
I was try to implement your formatter like numberPicker.setFormatter(new StepFormatter()) in sample code. http://imgur.com/bsQcaQu.png
It's working fine. http://imgur.com/OrzrK9S.png
What version that you are using?

from numberpicker.

kris-sum avatar kris-sum commented on May 26, 2024

No worries @ShawnLin013 :)
I have the number wrapping turned off, and the initial value gets set to a non-zero value, could that be it?
My gradles is using "com.shawnlin:number-picker:2.1.0"

for ( ... ) {
            
            (snip)

            mNumberPickers[i].setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            mNumberPickers[i].setFormatter(mStepFormatter);

            mNumberPickers[i].setMinValue(1);
            mNumberPickers[i].setMaxValue(maxValue);
            mNumberPickers[i].setValue((int) Math.floor(level / 5));

            mNumberPickers[i].setVisibility(View.VISIBLE);
            mNumberPickers[i].setWrapSelectorWheel(false);
            mNumberPickers[i].invalidate();
           
            mNumberPickers[i].setOnValueChangedListener( new NumberPicker.OnValueChangeListener() {
                private int colourIndex;
                @Override
                public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                    mBeaker.getLevels().set(colourIndex, newVal*5);
                    mBeaker.invalidate();
                    invalidateUI();
                }
                public NumberPicker.OnValueChangeListener init(int i) {
                    colourIndex = i;
                    return this;
                }
            }.init(i));

            i++;
        }

from numberpicker.

ShawnLin013 avatar ShawnLin013 commented on May 26, 2024

In this case, you should use setDisplayedValues instead of setFormatter.

int length = 10;
int level = 5;
String[] numbers = new String[length];
for (int i = 0; i < numbers.length; i++) {
    numbers[i] = String.valueOf((i + 1) * level);
}
numberPicker.setMinValue(1);
numberPicker.setMaxValue(length);
numberPicker.setDisplayedValues(numbers);
numberPicker.setValue(5);

from numberpicker.

kris-sum avatar kris-sum commented on May 26, 2024

Aye, i've switched to that, thanks.

from numberpicker.

Related Issues (20)

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.