Android edittext 检查布局if语句上是否存在EditText

Android edittext 检查布局if语句上是否存在EditText,android-edittext,Android Edittext,我知道如何使用以下方法检查编辑文本是否有文本 EditText etCode = (EditText) findViewById(R.id.et_code); String stringCode = etCode.getText().toString(); if(TextUtils.isEmpty(stringCode)) { etCode.setError("My Error Message"); return; } 在从同一编辑文本获取文本之前

我知道如何使用以下方法检查编辑文本是否有文本


EditText etCode = (EditText) findViewById(R.id.et_code);
String stringCode = etCode.getText().toString();

 if(TextUtils.isEmpty(stringCode)) {
    etCode.setError("My Error Message");
    return;
 }

在从同一编辑文本获取文本之前,我将文本设置为相同的etCode。下面的代码是我如何将文本从类设置为编辑文本


new OTPReceiver().setEditTextOtp(etCode);

OtPreciver类扫描到达手机的消息,然后将文本设置为etCode Edit text(编辑文本),我在其中阅读它们。我遇到的问题是,我导航到另一个包含etCode的片段,然后OtPreciver继续将收到的短信文本设置为Edit text(编辑文本),并发现它不可用,因为我们有导航到另一个片段,例如,在设置文本之前,是否有方法可以检查编辑文本etCode是否存在


if(etCode.isAvailabe){
   new OTPReceiver().setEditTextOtp(etCode);
}else{
  Toast.makeText(getActivity(), "We haven't found your edit text", Toast.LENGTH_SHORT).show();
}

或者类似的


if(etCode.isThere){
   new OTPReceiver().setEditTextOtp(etCode);
}else{
  Toast.makeText(getActivity(), "We haven't found your edit text", Toast.LENGTH_SHORT).show();
}