Android的NumberPicker隐藏增量和减量按钮 [英] Android NumberPicker hiding increment and decrement buttons

查看:676
本文介绍了Android的NumberPicker隐藏增量和减量按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 NumberPicker 并针对我11 API及以上(3.0及以上),所以我使用的是支持的 NumberPicker 。这是在一个计时器应用程序被使用。我希望能够隐藏随意的增加和减少按钮,这样隐时现的按钮不会占用空间布局。我试图做到这一点:

 查看增量= secs.getChildAt(0);
increment.setVisibility(View.GONE);
视图减量= secs.getChildAt(2);
decrement.setVisibility(View.GONE);

其中秒是我在定时器秒NumberPicker。如果我试图掩​​盖它显示号码的地方(一个EditText小部件),它隐藏得很好,但上面的code什么也不做。

所以,我的问题是,如何实现隐藏增量和减量按钮?我真的想避免自己的自定义选择器数量就像我在一些其他职位了解,但如果这是真正的唯一途径,我愿意尝试一下。

谢谢!

下面是额外的code的要求。
code中的onClick方法时启动秒表为:

 如果(stopPush)
{
STARTTIME = System.currentTimeMillis的() - elapsedTime;
}
其他
{
STARTTIME = System.currentTimeMillis的();
}
mHandler.removeCallbacks(startTimer所);
mHandler.postDelayed(startTimer所,0);

code处理能力秒表:

 私人的Runnable startTimer所=新的Runnable()
{
公共无效的run()
{
    elapsedTime = System.currentTimeMillis的() - startTime时;
    updateTimer(elapsedTime);
    mHandler.postDelayed(这一点,REFRESH_RATE);
}
};

code用于计算和更新秒表计时:

  this.millis =(INT)(elapsedTime / 100);
this.seconds =(int)的(elapsedTime / 1000);
this.minutes =(秒/ 60);
this.hours =(分钟/ 60);
米利斯=米利斯%10;
秒秒= 60%;
分钟=分钟%60;
小时=小时%24;
runOnUiThread(新的Runnable()
{
公共无效的run()
{
    hrs.setValue(小时);
}
});
runOnUiThread(新的Runnable()
{
公共无效的run()
{
    mins.setValue(分钟);
}
});
runOnUiThread(新的Runnable()
{
公共无效的run()
{
    secs.setValue(秒);
}
});
runOnUiThread(新的Runnable()
{
公共无效的run()
{
    mills.setValue((INT)米利斯);
}
});


解决方案

当你不提供有关numberpicker的MIN-和最大价值,按钮(通常)未显示。

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

解决方案

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

这篇关于Android的NumberPicker隐藏增量和减量按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆