Hi group,
I trying to use Datepicker widget to select the date and pass to
google gdata api to fetch calender events

private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year,
                                      int monthOfYear, int dayOfMonth)
{

                    mYear = year;
                    mMonth = monthOfYear+1; // why is that step up is
needed
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };

private void updateDisplay() {

        StringBuilder status= new StringBuilder(50);
        String y1=String.valueOf(mYear);
        String m1=String.valueOf(mMonth);
        if(m1.length()==1)
        {
                m1="0"+m1;
        }
        String d1=String.valueOf(mDay);
        if(d1.length()==1)
        {
                d1="0"+d1;
        }


        String startdate=y1+"-"+m1+"-"+d1+"T"+"00:00:00";
        //example out put for startdate:2009-02-12T00:00:00
        String enddate=y1+"-"+m1+"-"+d1+"T"+"23:59:59";

        try{
                myQuery.setMinimumStartTime(DateTime.parseDateTime(startdate));
                myQuery.setMaximumStartTime(DateTime.parseDateTime(enddate));;
                Feed resultFeed = myService.query(myQuery, Feed.class);
                for (int i = 0; i < resultFeed.getEntries().size(); i++) {
                          Entry entry =  resultFeed.getEntries().get(i);
                          status.append("\t" + entry.getTitle().getPlainText());

                                                }
           }catch(Exception e){System.out.println(e);}

           mDateDisplay.setText(status);

 }

I will be glad if someone clarifies few points

1. Why is that this step up is needed - > mMonth = monthOfYear+1;
2. DateTime.parseDateTime(String args) takes date format as
2009-02-12T00:00:00 and is there any other simple approach to convert
int values from Datepicker to required format,the one shown above
doesn't work .At present i hard-code  values to make it work ,like
        
myQuery.setMinimumStartTime(DateTime.parseDateTime("2010-02-12T00:00:00"));
        
myQuery.setMaximumStartTime(DateTime.parseDateTime("2010-03-12T23:59:59"));

3. The code works fine(when i hard code the as shown above) for the
very time of execution .when i clicked back button and again tried to
run the app ,resultFeed throws Null pointer exception.

I could appreciate your valuable suggestion to correct my mistakes.

Thanks
ganesh

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to