I cant seem to check my Edit text for empty insertion into my database. Here is my code. I am using the TextUtils.isEmpty to check but I keep creating empty info when the user just clicks add. I want the button to send the toast message if it is empty. What am I doing wrong.
public void onSaveButtonClicked() {
String description = mEditText.getText().toString();
if(TextUtils.isEmpty(mEditText.getText())){
Toast.makeText(this, "Please Record a Task", Toast.LENGTH_SHORT).show();
}
int priority = getPriorityFromViews();
Date date = new Date();
final TaskEntry task = new TaskEntry(description, priority, date);
AppExecutors.getInstance().diskIO().execute(() -> {
if (mTaskId == DEFAULT_TASK_ID ) {
// insert new task
mDb.taskDao().insertTask(task);
} else {
//update task
task.setId(mTaskId);
mDb.taskDao().updateTask(task);
}
finish();
});
}
如果要检查其是否为空,则想返回该内部,因此该函数在其为空时不会执行其余部分。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.