我有一个按钮和两个editTexts。 我想知道是否有人能告诉我如何检查editTexts活动; 如果两个editTexts都为空,则按钮可见,可以是透明但不可点击的。 有没有人知道改变可见性或使其无法点击的代码? 感谢
答案 0 :(得分:1)
您需要做的就是使用addTextChangedListener收听编辑文字,然后停用或隐藏按钮。
yourEditText = (EditText) findViewById(R.id.yourEditTextId);
yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// check the count here and hide your button in response either by hiding it or disabling it.
button.setEnabled(false);
}
});
答案 1 :(得分:0)
您应该在按钮上使用setEnabled(false);
使其无法点击。而是使用setEnabled(true);
来获得相反的行为
答案 2 :(得分:0)
您可以将按钮设置为不可点击 - 来自xml:
android:enabled="false"
来自代码:
button.setEnabled(false);
答案 3 :(得分:0)
你应该使用 addTextChangedListener ,正如Ahmad Kayyali所说。 并根据您的要求切换可见性,使用:
button.setVisibility(View.GONE);
button.setVisibility(View.VISIBLE);