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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:09:41+00:00 2026-06-04T09:09:41+00:00

I have attached my code below. i want to get dialogue of Date picker

  • 0

I have attached my code below. i want to get dialogue of Date picker on touch event event of Edit text. i am getting no error but also do not getting any Date dialogue.

Please Help me where i am wrong. Thanx in Advance.

String TAG = "AdvancedSearchActivity";
EditText txtArrCity, txtDepCity, txtDate, txtTime;
public String year, month, day;
public static final int DATE_DIALOG_ID = 1;
// OnDateSetListener dateListener;
String DATE;

/*
 * (non-Javadoc)
 * 
 * @see android.app.Activity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.advance_search);

    txtArrCity = (EditText) findViewById(R.id.edittxt_ArrCity);
    txtDepCity = (EditText) findViewById(R.id.edittxt_DepCity);
    txtDate = (EditText) findViewById(R.id.edittxt_Date);
    txtTime = (EditText) findViewById(R.id.edittxt_Time);

    Calendar cal = Calendar.getInstance();
    year = String.valueOf(cal.get(Calendar.YEAR));
    month = String.valueOf(cal.get(Calendar.MONTH));
    day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));

    Log.i(TAG, "Year" + year);
    Log.i(TAG, "month" + (month + 1));
    Log.i(TAG, "Day" + day);
    updateDate();

    txtDate.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG_ID);
            Log.i(TAG, "Inside On touch");
            return false;
        }
    });

}

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(TabSample.tabcontext,
                dateListener, Integer.parseInt(year),
                Integer.parseInt(month), Integer.parseInt(day));

    }
    return null;

}

// the callback received when the user "sets" the date in the dialog
private DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int years, int monthOfYear,
            int dayOfMonth) {
        // TODO Auto-generated method stub
        year = String.valueOf(years);
        month = String.valueOf(monthOfYear);
        day = String.valueOf(dayOfMonth);
        updateDate();
    }
};

private void updateDate() {

    month = String.valueOf((Integer.parseInt(month) + 1));
    if ((Integer.parseInt(month)) < 10) {
        Log.i(TAG, "@@@@@ month" + month);
        month = "0" + month;
        Log.i(TAG, "@@@@@ AFTER month" + month + " MONTH S" + month);
    }
    day = String.valueOf(day);
    if ((Integer.parseInt(day)) < 10) {
        day = "0" + day;
    }
    DATE = year + "-" + month + "-" + day;

    Log.i(TAG, "DATE : " + DATE);
    txtDate.setText(DATE);
}
  • 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-04T09:09:43+00:00Added an answer on June 4, 2026 at 9:09 am

    Try like this

     public class name extends Activity {   
         private EditText dob;
            static final int DATE_DIALOG_ID = 0;
            @Override
                protected Dialog onCreateDialog(int id) {
                    Calendar c = Calendar.getInstance();
                    int cyear = c.get(Calendar.YEAR);
                    int cmonth = c.get(Calendar.MONTH);
                    int cday = c.get(Calendar.DAY_OF_MONTH);
                    switch (id) {
                    case DATE_DIALOG_ID:
                        return new DatePickerDialog(this,  mDateSetListener,  cyear, cmonth, cday);
                    }
                    return null;
                }
                private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
                    // onDateSet method
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        String date_selected = String.valueOf(dayOfMonth)+" /"+String.valueOf(monthOfYear+1)+" /"+String.valueOf(year);
                        //Toast.makeText(getApplicationContext(), "Selected Date is ="+date_selected, Toast.LENGTH_SHORT).show();
                        dob.setText(date_selected);
                    }
                };
            @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.bankregform);
                dob=(EditText)findViewById(R.id.dob);
            /* For DOB EditText*/
                    dob.setOnTouchListener(new OnTouchListener(){ 
                        public boolean onTouch(View v, MotionEvent event) { 
                            if(v == dob)
                                showDialog(DATE_DIALOG_ID);
                            return false;              
                        }
                    });
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have attached an event to a text box using addEventListener . It works
I'm having problem with datagrid view. I have attached an image with the code
I have some debugging code that if executed while running with GBD attached should
I have a div which I have attached an onclick event to. in this
The javascript code is attached below. Two push pins are added to a Bing
I have built a simple registration form shown below and Iam trying to get
I have this (attached)code which works perfectly on all the AVDs I create with
I have attached the sample code which demonstrates the problem. I am checking this
Monotouch 5.0.2. Running the simple code below I get this in the output panel:
Currently I want to automate the running IE. I have successfully attached the running

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.