Permalink
Browse files

Fix edit bug

  • Loading branch information...
simonewebdesign committed Mar 8, 2013
1 parent ca7d50b commit 8ae15ba87daa082f18c48a1bb2bf08accab6b246
Showing with 14 additions and 9 deletions.
  1. +14 −9 src/com/example/todolist/MainActivity.java
@@ -87,31 +87,36 @@ public void onClick(View v) {
}
};
- public void addTask(){
-
- String task = myEditText.getText().toString();
+ public boolean addTask(){
+ String task = myEditText.getText().toString().trim();
+
if (Util.isNullOrEmpty(task)) {
// task is empty, show toast
Util.showToast(context, "You cannot leave it blank.");
+ return false;
} else {
int index = 0;
todoRows.add(index, new ToDoRow(task));
adapter.notifyDataSetChanged();
saveData();
myEditText.setText("");
+ return true;
}
}
public void editTask(ToDoRow row) {
-
- todoRows.remove(rowToEdit);
- addTask();
- myButton.setText("Add");
- action = "Insert";
- Util.showToast(context, "Task edited successfully!");
+
+ boolean added = addTask();
+
+ if (added) {
+ todoRows.remove(rowToEdit);
+ myButton.setText("Add");
+ action = "Insert";
+ Util.showToast(context, "Task edited successfully!");
+ }
}
@Override

0 comments on commit 8ae15ba

Please sign in to comment.