Java 输入其中一个文本后,如何设置不可编辑的其他编辑文本?
我的应用程序中有四个编辑文本 当我们在其中一个文本中写下其他三个编辑文本时,想让它们都不可编辑吗Java 输入其中一个文本后,如何设置不可编辑的其他编辑文本?,java,android,android-studio,if-statement,android-edittext,Java,Android,Android Studio,If Statement,Android Edittext,我的应用程序中有四个编辑文本 当我们在其中一个文本中写下其他三个编辑文本时,想让它们都不可编辑吗 如何实现这一点?您需要在所有编辑文本上添加文本监视程序,并在每个监视程序中禁用其他编辑文本。 你需要四个观察者 field1.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { // now check if text is not empty disable fi
如何实现这一点?您需要在所有编辑文本上添加文本监视程序,并在每个监视程序中禁用其他编辑文本。 你需要四个观察者
field1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// now check if text is not empty disable field 2, 3 ,4.
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
您可以将
TextChangedListener
添加到EditText
s,每次相应的EditText
的文本更改时都会触发该列表
您可以通过以下代码使任何EditText
不可编辑:
editText.setInputType(InputType.TYPE_NULL);
因此,您的整个代码将是:
editText1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
editText2.setInputType(InputType.TYPE_NULL);
editText3.setInputType(InputType.TYPE_NULL);
editText4.setInputType(InputType.TYPE_NULL);
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
剩下的3个
EditText
s将使用相同的代码。您应该提供这些代码才能找到帮助。@EmreDalkiran。。。这个问题已经完成了@HarshitSeksaria我的意思是代码示例op正在处理。