我有两个用于用户名和密码的edittext,我使用seterror方法显示错误,当它们都是空的。问题是当错误消息弹出在第二个字段密码字段),部分信息丢失。此错误仅适用于较旧的设备。如何确保错误不会发生在较旧的设备中。在android中使用seterror方法验证edittext
我的代码:
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;
}
}
当你说所显示的错误部分是因为它得到了屏幕的?或者只是它不完全出现 – zozelfelfo 2014-09-19 06:30:57
张贴截图 – 2014-09-19 06:31:17
可以请你张贴屏幕截图吗? – Umair 2014-09-19 06:34:15