user3525290:
私はアプリを作るために始めています。私は現在、1つのEditTextを持っています。どのように私はそれを必要とするのですか?何ものEditTextに入力されていない場合!メッセージはPlease Enter a username
画面上に点滅しなければならないが、それはまだ次のシーン/活動に行きます。長さが0の場合、私は提出停止私が公共のボイドに戻り偽を置くが、私は、次のメッセージを取得するにはどうすればよいですcannot return a value from a method with void result type
public void sendMessage(View view){
Intent intent = new Intent(this,DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
//Trim whitespace
message = message.trim();
//Checks if the message has anything.
if (message.length() == 0)
{
editText.setError("Please Enter a username!");
//return false;
}
intent.putExtra(EXTRA_MESSAGE,message);
startActivity(intent);
}
モハメド・アデル:
これを試して
string text=editText.getText().toString().trim();
if (TextUtils.isEmpty(text)){
editText.setError("Please Enter a username!");
}else {
//do something
}