gpt4 book ai didi

java - 防止 Textview android 中的负数 - 代码

转载 作者:行者123 更新时间:2023-12-01 12:07:23 24 4
gpt4 key购买 nike

是否可以通过在java中编写代码来停止在android中的TextView中获取负数。

我试过了

int up = 0;
TextView textview;

if (allowNagativeNumbers == false) {
if ( up < 0 )
{
up = 0;
textview.setText(0);
}
}

但它仍然允许负数。我不确定这段代码是否正确,但通过这段代码我的意思是每次 textview 中的 up/text 的值小于 0 例如-1然后将最多的值更改为0并使textview文本为0。

最佳答案

TextView 中显示您的号码之前,请对您的号码使用 Math.abs() 函数。此函数将为您提供绝对值。

关于java - 防止 Textview android 中的负数 - 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27483428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com