Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:03:08+00:00 2026-06-01T22:03:08+00:00

I am currently in the process of making a date/time picker class. Essentially, I

  • 0

I am currently in the process of making a date/time picker class. Essentially, I have created 3 radio buttons: ‘tomorrow’, ‘In 2 days’, and ‘next week’.

What I am looking to do is have these radio buttons automatically set the date picker ahead the respective amount of days (1, 2, and 7 days ahead).

I tried using the updateDate(int year, int month, int day) method to update my DatePicker when the user clicks the radio button, but nothing happens when any of the radio buttons are clicked.

Is there a specific way to change the datepicker’s displayed date WITHOUT using the the ticker buttons?

Here is my code for the class:

 package com.inviscidlabs.schooled;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class DateTimePicker extends Activity{


    private DatePicker datePicker;

    private RadioGroup dtpRadGroup;
    private RadioButton rTomorrow;
    private RadioButton rIn2Days;
    private RadioButton rNextWeek;


    private Calendar cNow;
    private Calendar c;


    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        //declare resources
        setContentView(R.layout.datetimepicker);
        dtpRadGroup=(RadioGroup) findViewById(R.id.dtp_radiogroup);
        rTomorrow=(RadioButton) findViewById(R.id.dtp_button_tomorrow);
        rIn2Days=(RadioButton) findViewById(R.id.dtp_button_twodays);
        rNextWeek= (RadioButton) findViewById(R.id.dtp_button_nextweek);
        datePicker= (DatePicker) findViewById(R.id.dtp_datepicker);

        cNow= Calendar.getInstance();
        cNow.setLenient(true);      c.setLenient(true);
        datePicker.init(cNow.get(Calendar.YEAR), cNow.get(Calendar.MONTH), cNow.get(Calendar.DAY_OF_MONTH), dListener);

    }

    public void onClick(View v){

        switch(v.getId()){

        case R.id.dtp_button_finished:

            break;
        }

    }

    public void onRadioButtonClicked(View v){
        c=Calendar.getInstance();



        switch(v.getId()){

        case R.id.dtp_button_tomorrow:
             c.add(Calendar.DAY_OF_YEAR, 1);
             datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));

            break;
        case R.id.dtp_button_twodays:
             c.add(Calendar.DAY_OF_YEAR, 2);
             datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            break;
        case R.id.dtp_button_nextweek:
             c.add(Calendar.DAY_OF_YEAR, 7);
             datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            break;
        }
    }





    private DatePicker.OnDateChangedListener dListener = new DatePicker.OnDateChangedListener() {

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

                Calendar cPickerDate = Calendar.getInstance();
                cPickerDate.set(year, monthOfYear, dayOfMonth);
                int dayOfYear = cPickerDate.get(Calendar.DAY_OF_YEAR);
                Log.v("day of year", String.valueOf(dayOfYear));



                //automatically checks radio buttons if user manually adjust picker
                if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+1){
                    rTomorrow.setChecked(true);
                }
                else if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+2){
                    rIn2Days.setChecked(true);
                }
                else if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+7){
                    rNextWeek.setChecked(true);
                } else {
                    dtpRadGroup.clearCheck();
                }

        }
    };





}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:03:10+00:00Added an answer on June 1, 2026 at 10:03 pm

    use the below modified code::::

    package com.inviscidlabs.schooled;
    
    import java.util.Calendar;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    
    public class DateTimePicker extends Activity{
    
        private static int TODAY = 0;
        private static int NEXTDAY = 1;
        private static int NEXTWEEK = 2;
    
        private DatePicker datePicker;
        private RadioGroup dtpRadGroup;
        private RadioButton rTomorrow;
        private RadioButton rIn2Days;
        private RadioButton rNextWeek;
    
    
        private Calendar cNow;
        private Calendar c;
    
    
        public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            //declare resources
            setContentView(R.layout.datetimepicker);
            dtpRadGroup=(RadioGroup) findViewById(R.id.dtp_radiogroup);
            rTomorrow=(RadioButton) findViewById(R.id.dtp_button_tomorrow);
            rIn2Days=(RadioButton) findViewById(R.id.dtp_button_twodays);
            rNextWeek= (RadioButton) findViewById(R.id.dtp_button_nextweek);
            datePicker= (DatePicker) findViewById(R.id.dtp_datepicker);
    
            cNow= Calendar.getInstance();
            cNow.setLenient(true);      c.setLenient(true);
            datePicker.init(cNow.get(Calendar.YEAR), cNow.get(Calendar.MONTH), cNow.get(Calendar.DAY_OF_MONTH), dListener);
    
        }
    
        public void onClick(View v){
    
            switch(v.getId()){
    
            case R.id.dtp_button_finished:
    
                break;
            }
    
        }
    
        public void onRadioButtonClicked(View v){
            c=Calendar.getInstance();
    
    
    
            switch(v.getId()){
    
            case R.id.dtp_button_tomorrow:
                 c.add(Calendar.DAY_OF_YEAR, 1);
                 showDialog(TODAY);
                // datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
    
                break;
            case R.id.dtp_button_twodays:
                 c.add(Calendar.DAY_OF_YEAR, 2);
                 showDialog(NEXTDAY);
                 //datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
                break;
            case R.id.dtp_button_nextweek:
                 c.add(Calendar.DAY_OF_YEAR, 7);
                 showDialog(NEXTWEEK);
                 //datePicker.updateDate(c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
                break;
            }
        }
    
        @Override
        protected Dialog onCreateDialog(int id) {
            final Calendar c = Calendar.getInstance();
            switch (id) {
            case TODAY:
                c.add(Calendar.DAY_OF_YEAR, 1);
            case NEXTDAY:
                c.add(Calendar.DAY_OF_YEAR, 2);
            case NEXTWEEK:
                c.add(Calendar.DAY_OF_YEAR, 7);
            }
            DatePickerDialog _date_repeat = new DatePickerDialog(this, mDateSetListener,c.get(Calendar.YEAR),c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)){
                    @Override
                    public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)
                    {   
                         Calendar cPickerDate = Calendar.getInstance();
                            cPickerDate.set(year, monthOfYear, dayOfMonth);
                            int dayOfYear = cPickerDate.get(Calendar.DAY_OF_YEAR);
                            Log.v("day of year", String.valueOf(dayOfYear));
    
    
    
                            //automatically checks radio buttons if user manually adjust picker
                            if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+1){
                                rTomorrow.setChecked(true);
                            }
                            else if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+2){
                                rIn2Days.setChecked(true);
                            }
                            else if(dayOfYear==cNow.get(Calendar.DAY_OF_YEAR)+7){
                                rNextWeek.setChecked(true);
                            } else {
                                dtpRadGroup.clearCheck();
                            }                   
                    }
                };  
            };
            return _date_repeat;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm in the process of making a custom solution for invoicing. I have
We currently have a process where we receive an inventory file from a vendor
I am currently in process of making our application Large Address Aware. As experience
I am currently in the process of making a WordPress Plugin which is going
I am currently in the process of making a snake game using VB.NET... I
I am currently in the process of designing a database. I have a table
I'm in the process of making a music app and I'm currently working on
I am currently in the process of creating my own blog and I have
I am currently in the process of making a new ASP.net MVC website, and
I am currently in the process of making an embedded system port of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.