Android NumberPicker hides increase and decrease buttons

I am using NumberPicker and targeting API 11 and above (3.0 and above), so I am using the supported NumberPicker . This is used in the timer application. I want to be able to hide the increase and decrease buttons as desired so that the buttons do not take up space in the layout when hiding. I tried to do this:

View increment = secs.getChildAt(0); increment.setVisibility(View.GONE); View decrement = secs.getChildAt(2); decrement.setVisibility(View.GONE); 

where secs is my NumberPicker in seconds in the timer. If I try to hide the place where it displays the number (EditText widget), it hides just fine, but the code above does nothing.

So my question is: how do I hide the increase and decrease buttons? I would really like for me not to make my own number collector, as I read in some other posts, but if this is really the only way, I want to try it.

Thanks!

Here is an additional code as requested. The code in the onClick method when starting the stopwatch:

 if (stopPush) { startTime = System.currentTimeMillis() - elapsedTime; } else { startTime = System.currentTimeMillis(); } mHandler.removeCallbacks(startTimer); mHandler.postDelayed(startTimer, 0); 

Code that handles the stopwatch:

 private Runnable startTimer = new Runnable() { public void run() { elapsedTime = System.currentTimeMillis() - startTime; updateTimer(elapsedTime); mHandler.postDelayed(this, REFRESH_RATE); } }; 

Code for calculating and updating the stopwatch time:

 this.millis = (int) (elapsedTime / 100); this.seconds = (int) (elapsedTime / 1000); this.minutes = (seconds / 60); this.hours = (minutes / 60); millis = millis % 10; seconds = seconds % 60; minutes = minutes % 60; hours = hours % 24; runOnUiThread(new Runnable() { public void run() { hrs.setValue(hours); } }); runOnUiThread(new Runnable() { public void run() { mins.setValue(minutes); } }); runOnUiThread(new Runnable() { public void run() { secs.setValue(seconds); } }); runOnUiThread(new Runnable() { public void run() { mills.setValue((int) millis); } }); 
+6
source share
2 answers

If you have not indicated the minimum and maximum values ​​on the digital icon, the buttons (usually) are not displayed.

+4
source

Developer site says

NumberPicker is a widget that allows the user to select a number from a predefined range. There are two options for this widget, and the one presented to the user depends on the current theme.

If the current theme is obtained from Theme , the widget displays the current value as an editable input field with an increase button and a decrease button. A long press of the buttons allows you to quickly change the current value. Clicking on the input field allows you to enter the desired value.

If the current theme is derived from Theme_Holo or Theme_Holo_Light , the widget represents the current value as an editable input field with a lower value above and a larger value below. Pressing a smaller or larger value selects it, animating the numerical axis up or down to make the selected value current. Moving up or down allows multiple increments or decreases of the current value. Long press on smaller and larger values ​​also allows you to quickly change the current value. Clicking on the current value allows you to enter the desired value.

So you can try changing the subject.

0
source

Source: https://habr.com/ru/post/916962/


All Articles