反转滚动方向NumberPicker

时间:2017-10-17 19:24:16

标签: android numberpicker

如何反转NumberPicker的滚动方向

enter image description here

我想将0高于0

1 个答案:

答案 0 :(得分:0)

一种简单的onCreate方法......

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.something);
    final TextView tv = (TextView) findViewById(R.id.tv);
    NumberPicker np = (NumberPicker) findViewById(R.id.np);

    final String[] values = {"1", "0"};

    np.setMinValue(0);
    np.setMaxValue(values.length - 1);
    np.setDisplayedValues(values);
    np.setWrapSelectorWheel(true);
    np.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            String result = "Currently selected value:" + values[newVal];
            tv.setText(result);
        }
    });
}

...还有一个简单的something.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <NumberPicker
        android:id="@+id/np"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/np" />
</RelativeLayout>