]> Johnzone git - dienst_android.git/commitdiff
datepicker working
authorJohn Janus <john.janus@haw-hamburg.de>
Sat, 6 Apr 2013 21:22:08 +0000 (23:22 +0200)
committerJohn Janus <john.janus@haw-hamburg.de>
Sat, 6 Apr 2013 21:22:08 +0000 (23:22 +0200)
res/layout/activity_main.xml
src/de/rhinapotheke/notdienst/DBConnector.java [new file with mode: 0644]
src/de/rhinapotheke/notdienst/MainActivity.java

index 577b778db3391fb74c058984e1898d6715ae991f..50ceb5d2e2ce5c3562908e73186fa91c9e29d2ad 100644 (file)
                     android:id="@+id/prev_date"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:onClick="prevDate"
                     android:text="@string/prev" />
 
                 <Button
                     android:id="@+id/changeDate"
                     android:layout_width="wrap_content"
-                    android:layout_height="wrap_content" />
+                    android:layout_height="wrap_content"
+                    android:text="default"
+                    android:onClick="chooseDate" />
 
                 <Button
                     android:id="@+id/next_date"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
+                    android:onClick="nextDate"
                     android:text="@string/next" />
             </LinearLayout>
 
diff --git a/src/de/rhinapotheke/notdienst/DBConnector.java b/src/de/rhinapotheke/notdienst/DBConnector.java
new file mode 100644 (file)
index 0000000..1c0bc2a
--- /dev/null
@@ -0,0 +1,28 @@
+package de.rhinapotheke.notdienst;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteDatabase.CursorFactory;
+import android.database.sqlite.SQLiteOpenHelper;
+
+public class DBConnector extends SQLiteOpenHelper {
+
+       private static final String DBNAME = "notdienst.db";
+       public DBConnector(Context context) {
+               super(context, DBNAME, null, 1);
+               // TODO Auto-generated constructor stub
+       }
+
+       @Override
+       public void onCreate(SQLiteDatabase arg0) {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
+               // TODO Auto-generated method stub
+
+       }
+
+}
index e9d210d486dc5da4cf836959cdb8723b9a539cbe..47cf9f53093c704be76f0f92998d410f20eb6989 100644 (file)
@@ -2,22 +2,82 @@ package de.rhinapotheke.notdienst;
 
 import android.os.Bundle;
 import android.app.Activity;
+import java.text.DateFormat;
 import android.view.Menu;
+import android.view.View;
+import android.widget.Button;
+import android.widget.DatePicker;
+import android.widget.TextView;
+
+import java.util.Calendar;
+import android.app.DatePickerDialog;
 
 public class MainActivity extends Activity {
 
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_main);
-    }
+  Calendar cal;
+  DateFormat fmtDate;
+  Button dateLabel;
+  DBConnector not;
+
+  @Override
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    
+    cal = Calendar.getInstance();
+    fmtDate = DateFormat.getDateInstance();
+    setContentView(R.layout.activity_main);
+    dateLabel = (Button) findViewById(R.id.changeDate);
+    updateDateLabel();
+  }
+
+
+  @Override
+  public boolean onCreateOptionsMenu(Menu menu) {
+    // Inflate the menu; this adds items to the action bar if it is present.
+    getMenuInflater().inflate(R.menu.main, menu);
+    return true;
+  }
+
+  public void chooseDate (View v) {
+    new DatePickerDialog(MainActivity.this, d, 
+        cal.get(Calendar.YEAR), 
+        cal.get(Calendar.MONTH),
+        cal.get(Calendar.DAY_OF_MONTH)).show();
+  }
 
+  DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {
 
     @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        // Inflate the menu; this adds items to the action bar if it is present.
-        getMenuInflater().inflate(R.menu.main, menu);
-        return true;
+    public void onDateSet(DatePicker view, int year, int monthOfYear,
+        int dayOfMonth) {
+
+      cal.set(Calendar.YEAR, year);
+      cal.set(Calendar.MONTH, monthOfYear);
+      cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+
+      updateDateLabel();
+
+
     }
-    
+  };
+  
+  public void prevDate(View v) {
+    this.cal.add(Calendar.DAY_OF_MONTH, -1);
+    updateDateLabel();
+  }
+  
+  public void nextDate(View v) {
+    this.cal.add(Calendar.DAY_OF_MONTH, 1);
+    updateDateLabel();
+  }
+  
+
+  private void updateDateLabel() {
+    dateLabel.setText(fmtDate.format(cal.getTime()));
+    //dateLabel.setText(fmtDate.format(cal.getTime()));
+    //cal.get(Calendar.DAY_OF_MONTH) + " "
+    //      + cal.get(Calendar.DAY_OF_MONTH) + " "
+    //    + cal.get(Calendar.YEAR));
+
+  }
 }