英文:
Cannot resolve method makeText in Android
问题
尝试 1:
if ((fieldvalue.getText().toString()).matches("")) {
Toast.makeText(this, "您未输入用户名",
Toast.LENGTH_SHORT).show();
return;
}
尝试 2:
if ((fieldvalue.getText().toString()).matches("")) {
public static Toast makeText (this, "您未输入用户名",
Toast.LENGTH_SHORT);
return;
}
注意:尝试 2 中的代码似乎存在错误,无法正确执行。
英文:
I was trying to play with an android toast. But encountered a problem saying Cannot resolve method makeText
. I searched and found many answers but not a single worked for me.
Try 1:
if ((fieldvalue.getText().toString()).matches("")) {
Toast.makeText(this, "You did not enter a username",
Toast.LENGTH_SHORT).show();
return;
}
Try 2:
if ((fieldvalue.getText().toString()).matches("")) {
public static Toast makeText (this, "You did not enter a username",
Toast.LENGTH_SHORT);
return;
}
答案1
得分: 1
尝试使用isEmpty()
。同时确保使用.this
来定义activityclass
,例如yourclass.this
。
if (fieldvalue.getText().toString().isEmpty()) {
Toast.makeText(youractivity.this, "您未输入用户名!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(youractivity.this, "成功! :)", Toast.LENGTH_SHORT).show();
}
英文:
Try using isEmpty()
. Also make sure to define the activityclass with .this
like yourclass.this
.
if(fieldvalue.getText().toString().isEmpty()) {
Toast.makeText(youractivity.this, "You did not enter a username!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(youractivity.this, "Success! :)", Toast.LENGTH_SHORT).show();
}
答案2
得分: -2
Sure, here's the translated code:
if (fieldvalue.getText().toString().trim().isEmpty()) {
Toast.makeText(this, "您未输入用户名", Toast.LENGTH_SHORT).show();
return;
}
英文:
if (fieldvalue.getText().toString().trim().isEmpty()) {
Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
return;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论