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>
--- /dev/null
+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
+
+ }
+
+}
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));
+
+ }
}