Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 输入其中一个文本后,如何设置不可编辑的其他编辑文本?_Java_Android_Android Studio_If Statement_Android Edittext - Fatal编程技术网

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正在处理。