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 9228369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:18:25+00:00 2026-06-18T05:18:25+00:00

I have the following code: public void startDatePickerDialog(View v) { DatePickerFragment newFragment = new

  • 0

I have the following code:

public void startDatePickerDialog(View v) {
    DatePickerFragment newFragment = new DatePickerFragment();
    newFragment.setType("start");
    newFragment.show(getSupportFragmentManager(), "startDatePicker");
}

with DatePickerFragment

    private String type = "none";

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    // Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, year, month, day);
}

@Override
public void onCancel(DialogInterface dialog) {
    Toast.makeText(getActivity(), "works?", Toast.LENGTH_LONG).show();
    if (type.equals("start")) {
        EditText e = (EditText) getActivity().findViewById(
                R.id.date_of_task);
        e.setText("");
    } else {
        EditText e = (EditText) getActivity().findViewById(
                R.id.deadlineDate);
        e.setText("");
    }
    super.onCancel(dialog);
}

public void setType(String t) {
    type = t;
}

@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
    if (type.equals("start")) {
        EditText e = (EditText) getActivity().findViewById(
                R.id.date_of_task);
        e.setText("" + day + "." + (month + 1) + "." + year);
    } else {
        EditText e = (EditText) getActivity().findViewById(
                R.id.deadlineDate);
        e.setText("" + day + "." + (month + 1) + "." + year);
    }
}

My Problem is now that onCancel doesn’t work. Therefore I want to add a Button on the DialogFragment which causes the action in onCreate. How can I add a button or how can I solve this problem.

  • 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-18T05:18:27+00:00Added an answer on June 18, 2026 at 5:18 am

    There is a bug with the date/time pickerdialog. it is something like this :

    now :
    click on OK – the date gets set twice
    click cancel – the date gets cleared then set
    click back – date gets set once

    expected :
    click OK – date gets set once
    click Cancel – date gets reset
    click back – ntng and it retains the state as it was

    As a work-around, you could keep a counter that would get set the first time you call the OnDateSetListener and if the counter is > 1 then return and reset counter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public void setupScreen() { view.runOnUiThread(new Runnable() { public void
I have the following code: public void run() { try { logger.info(Looking for new
SO I have the following code public void rand(int N){ double[]x=new double[N]; double[]y=new double[N];
I have the following code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_database); db=new DBAdapter(this);
I have the following code: public void click(View v) { Button b = (Button)
I have following code: public static void ProcessStep(Action action) { //do something here if
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: public void disconnect() { running = false; if(thread !=
I have the following code: public void Dispose() { bool append = true; using(var
I have the following code: public void BeginConvert(object data) { ConverterData cObject = (ConverterData)data;

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.