我想创建一个只有少数编辑文本字段和一个按钮的 Activity ,在填充这些字段中最重要的字段之前,该按钮应该被禁用。这是我正在使用的代码,但按钮一直处于禁用状态:
doneButton implementation
if((isEmpty(inputType)) || (isEmpty(inputAmount)) || (isEmpty(inputSupplier)))
doneButton.Enabled = false;
else
doneButton.Enabled = true;
这是 isEmpty() 方法的代码,它检查编辑文本是否为空:
private Boolean isEmpty(EditText etText) {
return etText.Text.ToString().Length == 0;
}
提前致谢! :)
最佳答案
为什么不使用 TextChanged 事件:
EditText input = FindViewById<EditText>(Resource.Id.editText1);
input.TextChanged += input_TextChanged;
然后为它定义事件处理器?
private void input_TextChanged(object sender, TextChangedEventArgs e)
{
Console.WriteLine("input text changed");
// if text bigger than 0, enable the button, otherwise disable it
}
更干净恕我直言。
关于c# - 填充编辑文本后启用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25310689/