Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NumberPicker hiding increment and decrement buttons

Tags:

java

android

I am using a NumberPicker and am targeting API 11 and above (3.0 and up), so I am using the supported NumberPicker. This is being used in a timer application. I want to be able to hide the increment and decrement buttons at will so that the buttons will not take up space in the layout when hidden. I have attempted 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 for seconds in the timer. If I try to hide the place where it displays the number (an EditText widget) it hides just fine, but the above code does nothing.

So, my question is, how do I accomplish hiding the increment and decrement buttons? I would really like to avoid making my own custom number picker like I have read about in some other posts, but if that is truly the only way I'm willing to try it.

Thanks!

Here is additional code as requested. Code in onClick method for when stopwatch is started:

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

Code that handles stopwatch abilities:

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

Code for calculating and updating 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);
}
});
like image 780
Amara Ernst Avatar asked May 30 '12 01:05

Amara Ernst


1 Answers

When you do not provide the min- and max-value on the numberpicker, the buttons are (normally) not shown.

like image 159
barrel Avatar answered Oct 21 '22 17:10

barrel