在Android中怎么判断输入的字符不为空,就是在EditText中不输入东西,在提交时 要跳出提示 ,这个怎么做

用toast进行提示。。。。怎么做??
2024-12-26 08:36:07
推荐回答(2个)
回答1:

EditText editText=(EditText)findViewById(R.id...);
if("".equals(editText.getText().toString())||editText.getText().toString()==null){
Toast toast=Toast.makeText(MainActivity.this, "不能为空", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
return;
}

回答2:

String newpwd = edittext.getText().toString().trim();
if(newpwd.equals(""))
{
Toast.makeText(MainActivity.this, "请填写", Toast.LENGTH_LONG);
return;
}