【发布时间】:2014-10-24 14:59:10
【问题描述】:
我有一个 TextWatcher,它可以在所有 EditTexts 长度()都为 != 0 时启用一个按钮。我现在想添加一个功能,以确保数字为正数。我尝试在另一个 if() 中放置一个新的 if() 来检查是否 >0 但由于某种原因它不起作用。
所以我需要确保所有 EditText 不为空并且已输入正数,然后启用该数字。
这就是我所拥有的,
public TextWatcher localWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
// When the text is edited, I want to check if all textViews are filled
@Override
public void afterTextChanged(Editable s) {
// Check if any of the TextViews are == 0, if so the button remains disabled
if (et1local.getText().toString().length() == 0
|| et2local.getText().toString().length() == 0
|| et3local.getText().toString().length() == 0
|| et4local.getText().toString().length() == 0
|| et5local.getText().toString().length() == 0
|| et6local.getText().toString().length() == 0
|| et7local.getText().toString().length() == 0
|| et8local.getText().toString().length() == 0
|| et9local.getText().toString().length() == 0) {
if(et1local){
localCalculateButton.setEnabled(false);
}
}
// When all are filled enable the button
else {
localCalculateButton.setEnabled(true);
}
}
};
这很好,但是如何检查数字是否为正,任何帮助都非常感谢。
【问题讨论】:
-
把“-”换成“”怎么样?
标签: java android textwatcher