I want to prohibit sending empty text, but even the code field is filled, it again shows error text.

public class elaqemesage extends AppCompatActivity implements View.OnClickListener int etN; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.qebul); textsoname= (EditText) findViewById(R.id.textsoname); public void onClick(View v) { if (textsoname.getText().length() == 0) etN = 0; if ((etN == 0)){ textsoname.setError("Заполните Пустое Поле"); } else { mymetho(); } } 
  • Where textsoname variable textsoname come from? - iksuy
  • written in oncreate - elik
  • What is "etN" before this line: "if (textsoname.getText (). Length () == 0) etN = 0;" - Valera Kvip
  • int etN; Pyropsian - elik
  • one
    I responded by giving solutions - Valera Kvip

1 answer 1

I think the problem is that etN is always 0.

Try this:

 public void onClick(View v) { if (textsoname.getText().length() == 0){ textsoname.setError("Заполните Пустое Поле"); } else { mymetho(); } } 

or

  public void onClick(View v) { if (textsoname.getText().length() == 0) etN = 0; if ((etN == 0)){ etN = 1; textsoname.setError("Заполните Пустое Поле"); } else { mymetho(); } } 
  • I'll try to see) - elik
  • Of course the first option. The second kind of hints that this code was not without a Hindu - the etN variable is completely out of place. - pavlofff
  • Well, this is just in case the TC has removed some of the code or etN is still used somewhere else. - Valera Kvip