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); } });
source share