Skip to content

Commit 051f672

Browse files
committed
Todo with categories
1 parent 35d2d60 commit 051f672

11 files changed

Lines changed: 149 additions & 102 deletions

File tree

‎de.vogella.android.todos/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="de.vogella.android.todos" android:versionCode="1"
44
android:versionName="1.0">
5-
<application android:icon="@drawable/icon" android:label="@string/app_name">
5+
<application android:icon="@drawable/todo" android:label="@string/app_name">
66
<activity android:name=".Todos" android:label="@string/app_name">
77
<intent-filter>
88
<action android:name="android.intent.action.MAIN" />
2.8 KB
Loading
1.68 KB
Loading
2.06 KB
Loading

‎de.vogella.android.todos/res/layout/todo_edit.xml‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
android:layout_height="fill_parent">
55

66

7+
<Spinner android:id="@+id/category" android:layout_width="wrap_content"
8+
android:layout_height="wrap_content" android:entries="@array/priorities"></Spinner>
79
<LinearLayout android:id="@+id/LinearLayout01"
810
android:layout_height="wrap_content" android:layout_width="fill_parent">
9-
<EditText android:layout_height="wrap_content" android:id="@+id/todo_edit_summary" android:layout_weight="1" android:layout_width="wrap_content" android:hint="Summary"></EditText>
11+
<EditText android:layout_height="wrap_content" android:id="@+id/todo_edit_summary"
12+
android:layout_weight="1" android:layout_width="wrap_content"
13+
android:hint="Summary"></EditText>
14+
1015
</LinearLayout>
1116

12-
13-
<EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:id="@+id/todo_edit_description" android:hint="Description"></EditText>
17+
18+
<EditText android:layout_width="fill_parent"
19+
android:layout_height="fill_parent" android:layout_weight="1"
20+
android:id="@+id/todo_edit_description" android:hint="Description"></EditText>
1421
<Button android:layout_width="wrap_content"
1522
android:layout_height="wrap_content" android:id="@+id/todo_edit_button"
1623
android:text="@string/todo_edit_confirm"></Button>

‎de.vogella.android.todos/res/layout/todo_list.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
android:orientation="vertical" android:layout_width="fill_parent"
44
android:layout_height="fill_parent" android:background="@color/listcolor">
55
<ListView android:id="@android:id/list" android:layout_width="wrap_content"
6-
android:layout_height="wrap_content" />
6+
android:layout_height="wrap_content" ></ListView>
77
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
88
android:layout_height="wrap_content" android:text="@string/no_todos" />
9+
910
</LinearLayout>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="priorities"><item>Urgent</item>
4+
<item>Reminder</item>
5+
</string-array>
6+
</resources>

‎de.vogella.android.todos/src/de/vogella/android/todos/TodoEdit.java‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@
33
import android.app.Activity;
44
import android.database.Cursor;
55
import android.os.Bundle;
6+
import android.util.Log;
67
import android.view.View;
78
import android.widget.Button;
89
import android.widget.EditText;
10+
import android.widget.Spinner;
911
import de.vogella.android.todos.database.TodoDbAdapter;
1012

1113
public class TodoEdit extends Activity {
1214
private EditText mTitleText;
1315
private EditText mBodyText;
1416
private Long mRowId;
1517
private TodoDbAdapter mDbHelper;
18+
private Spinner mCategory;
1619

1720
@Override
1821
protected void onCreate(Bundle bundle) {
1922
super.onCreate(bundle);
20-
mDbHelper = new TodoDbAdapter(this);
21-
mDbHelper.open();
23+
mDbHelper = new TodoDbAdapter(this);
24+
mDbHelper.open();
2225
setContentView(R.layout.todo_edit);
26+
mCategory = (Spinner) findViewById(R.id.category);
2327
mTitleText = (EditText) findViewById(R.id.todo_edit_summary);
2428
mBodyText = (EditText) findViewById(R.id.todo_edit_description);
29+
2530
Button confirmButton = (Button) findViewById(R.id.todo_edit_button);
2631
mRowId = null;
2732
Bundle extras = getIntent().getExtras();
@@ -44,6 +49,18 @@ private void populateFields() {
4449
if (mRowId != null) {
4550
Cursor todo = mDbHelper.fetchTodo(mRowId);
4651
startManagingCursor(todo);
52+
String category = todo.getString(todo
53+
.getColumnIndexOrThrow(TodoDbAdapter.KEY_CATEGORY));
54+
55+
for (int i=0; i<mCategory.getCount();i++){
56+
57+
String s = (String) mCategory.getItemAtPosition(i);
58+
Log.e(null, s +" " + category);
59+
if (s.equalsIgnoreCase(category)){
60+
mCategory.setSelection(i);
61+
}
62+
}
63+
4764
mTitleText.setText(todo.getString(todo
4865
.getColumnIndexOrThrow(TodoDbAdapter.KEY_SUMMARY)));
4966
mBodyText.setText(todo.getString(todo
@@ -70,16 +87,18 @@ protected void onResume() {
7087
}
7188

7289
private void saveState() {
90+
String category = (String) mCategory.getSelectedItem();
7391
String summary = mTitleText.getText().toString();
7492
String description = mBodyText.getText().toString();
93+
7594

7695
if (mRowId == null) {
77-
long id = mDbHelper.createTodo(summary, description);
96+
long id = mDbHelper.createTodo(category, summary, description);
7897
if (id > 0) {
7998
mRowId = id;
8099
}
81100
} else {
82-
mDbHelper.updateTodo(mRowId, summary, description);
101+
mDbHelper.updateTodo(mRowId, category, summary, description);
83102
}
84103
}
85104
}

‎de.vogella.android.todos/src/de/vogella/android/todos/Todos.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public void onCreate(Bundle savedInstanceState) {
3030
dbHelper = new TodoDbAdapter(this);
3131
dbHelper.open();
3232
fillData();
33-
System.out.println("Hallo");
3433
registerForContextMenu(getListView());
3534
}
3635

‎de.vogella.android.todos/src/de/vogella/android/todos/database/DatabaseHelper.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
public class DatabaseHelper extends SQLiteOpenHelper {
99
private static final String TAG = "DatabaseAdapter";
1010
private static final String DATABASE_NAME = "applicationdata";
11-
12-
private static final int DATABASE_VERSION = 2;
11+
12+
private static final int DATABASE_VERSION = 3;
1313

1414
// Database creation sql statement
1515
private static final String DATABASE_CREATE = "create table todo (_id integer primary key autoincrement, "
16-
+ "summary text not null, description text not null);";
16+
+ "category text not null, summary text not null, description text not null);";
1717

1818
public DatabaseHelper(Context context) {
1919
super(context, DATABASE_NAME, null, DATABASE_VERSION);

0 commit comments

Comments
 (0)