1

With the default android Number Picker, when there is only 0 and 1 inside it, the UI doesn't react properly (freeze or glitch). Is there a possibility to extends from Number Picker to have as displayed Values [0,1,0] ?Thanks!!

Hemant Parmar
  • 3,552
  • 7
  • 22
  • 45
Bénédicte Lagouge
  • 472
  • 1
  • 7
  • 24

2 Answers2

0

I think you can do it using a compound view. I found this very helpful https://code.tutsplus.com/tutorials/creating-compound-views-on-android--cms-22889

eliamyro
  • 311
  • 1
  • 4
  • 19
0

You can create custom value using NumberPicker. You can use something like this:

Layout:

    <android.widget.NumberPicker
        android:id="@+id/custom_np"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Logic:

NumberPicker numberPicker = view.findViewById(R.id.custom_np);
...
// Define the text to be displayed in NumberPicker
String[] texts = {"0", "1"};
numberPicker.setMinValue(0);
numberPicker.setMaxValue(texts.length - 1);
numberPicker.setDisplayedValues(texts);
numberPicker.setWrapSelectorWheel(true);
ישו אוהב אותך
  • 22,515
  • 9
  • 59
  • 80