title: Using seterror method for validating edittext in android
body: <p>I have two edittexts for username and password ,I use the seterror method to show an error when both of them are empty.The problem is when the error message pops up in the second field(the password field) , part of the message is missing.This bug is there only on older devices.How do i ensure that the error does not happen in older devices.</p>
  
  <p>My code:</p>
  
  <pre><code>public class SignInPage extends Activity {
  
      EditText txtusername,txtpassword;
      Button btnlogin;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.signinpage);
          txtusername=(EditText) findViewById(R.id.txtusername);
          txtpassword=(EditText) findViewById(R.id.txtpassword);
          btnlogin=(Button) findViewById(R.id.btnlogin);
          btnlogin.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  if(txtusername.getText().toString().trim().equals(""))
                  {
                      txtusername.setError("Username is mandatory");
                      txtusername.requestFocus();
                  }
                  if(txtpassword.getText().toString().trim().equals(""))
                  {
                      txtpassword.setError("Password is mandatory");
                      txtpassword.requestFocus();
                  }
                  else
                  {
                      Toast.makeText(getApplicationContext(),"Checking with server",Toast.LENGTH_LONG).show();
                  }
              }
          });
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>