Git Product home page Git Product logo

Comments (2)

Carbs0126 avatar Carbs0126 commented on July 21, 2024 1

感谢支持!
1.可以不使用xml配置,在java中赋值给它:

        //赋值给要添加的string[ ]
        int from = 1970;
        int to = 2020;
        int size = to - from + 1;
        final String[] values = new String[size];
        for(int i = 0; i < size; i++){
            values[i] = String.valueOf(from + i);
        }
        //添加内容至NumberPickerView
        mNumberPickerView.setDisplayedValues(values);
        mNumberPickerView.setMinValue(0);//better not set minValue a negative number.
        mNumberPickerView.setMaxValue(values.length - 1);
        mNumberPickerView.setValue(2016 - 1970);//这里设置默认显示的初始值,这个value是相对minvalue的

        mNumberPickerView.setOnValueChangedListener(new NumberPickerView.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPickerView picker, int oldVal, int newVal) {
                Toast.makeText(getApplicationContext(),"picked content :  " + values[newVal], Toast.LENGTH_SHORT).show();
            }
        });

2.由于这个控件的api和NumberPicker一致,因此当初没有添加输入数值范围自动生成字符数组的功能,所以可以先java/xml 生成string[ ]。
3.对于textarray小于value范围后,会报异常,这也和numberpicker一致。否则控件读取信息并显示时,会遇到问题。numberpicker在更换string[ ]时,没有提供简便的方法,每次更新string[ ]时都需要先做范围判断,并采取两种不同顺序的设置maxValue和displayValue。在NumberPickerView中,我加上了一个方法

refreshByNewDisplayedValues(String[] display)

只需要这样一个方法就可以及时刷新其中的内容,当然前提是,minValue的值固定为0

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on July 21, 2024

不客气

from numberpickerview.

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.