Hi:

I am wanting to use the 
CalendarView<http://developer.android.com/reference/android/widget/CalendarView.html>widget
 to let users of my app choose a date, rather than using the 
DatePicker<http://developer.android.com/reference/android/widget/DatePicker.html>.
 
 The date must be in the future.  Here is my layout XML:

*<?xml version="1.0" encoding="utf-8"?>*
*<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"*
*    android:orientation="vertical"*
*    android:layout_width="fill_parent"*
*    android:layout_height="fill_parent"*
*    >*
*  <CalendarView*
*      android:id="@+id/calview"*
*      android:layout_width="320dp"*
*      android:layout_height="320dp"*
*      />*
*</LinearLayout>*


My first thought for how to limit the widget to dates in the future was to 
set the minimum date to the current date, but that doesn't seem to work: 
Here is what I tried:

*package test.cal;*


*import android.app.Activity;*
*import android.os.Bundle;*
*import android.widget.CalendarView;*


*public class CalTestActivity extends Activity **{*
*    @Override*
*    public void onCreate(Bundle savedInstanceState) {*
*        super.onCreate(savedInstanceState);*
*        setContentView(R.layout.main);*
*        CalendarView calView = (CalendarView)findViewById(R.id.calview);*
*        calView.setMinDate((new java.util.Date()).getTime());*
*    }*
*}*


The calendar is not displayed; rather I get a runtime error complaining 
that the fromDate does not precede the toDate, and indicating that both are 
the current date, even though as you can see from the code above I am only 
setting the minDate.

So the next thing I tried was to set the minimum date to yesterday.  Here 
is the code:

*package test.cal;*


*import android.app.Activity;*
*import android.os.Bundle;*
*import android.widget.CalendarView;*
*import android.util.Log;*
*import java.util.Date;*
*
*
*public class CalTestActivity extends Activity **{*
*    @Override*
*    public void onCreate(Bundle savedInstanceState) {*
*        super.onCreate(savedInstanceState);*
*        setContentView(R.layout.main);*
*        CalendarView calView = (CalendarView)findViewById(R.id.calview);*
*        calView.setMinDate((new Date()).getTime() - 86400000L);*
*        Log.d("CalTest", "fromDate is " + new Date(calView.getMinDate()));*
*        Log.d("CalTest", "toDate is " + new Date(calView.getMaxDate()));*
*    }*
*}*


Now what happens is that the calendar is displayed, but I cannot swipe 
forward in time and if I swipe backwards, it immediately jumps to September 
1964, and then if I swipe forwards it will not go any further than October 
1964!

The output of the two logging statements you can see in my code indicate 
that the minimum date is correctly 24 hours ago, and the maximum date is 
December 31st, 2100, so why is the widget not behaving in accordance with 
those values?

I have tried this both with a device (HTC Doubleshot) and an emulator; both 
yield the same result.  I am using API level 15.

If anyone can tell me what I'm missing, I will be most grateful.  Thank you 
very much.

--
Adam Mackler

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to