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

  • Home
  • SEARCH
  • 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 8192173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:59+00:00 2026-06-07T04:06:59+00:00

i have a edit text box and i have call ontouchlistener it show a

  • 0

i have a edit text box and i have call ontouchlistener it show a custom dialog and when i click setdate button the date on date picker should set on the edit text and the dialog should get dismiss. but i dont know how to get date from date picker and how to set in edit text box. i am getting error in date.init( year, monthOfYear, dayOfMonth, new MyOnDateChangedListener() ); and the error isMultiple markers at this line
– dayOfMonth cannot be resolved to a
variable
– year cannot be resolved to a variable
– monthOfYear cannot be resolved to a
variable

 et4.setOnTouchListener(new OnTouchListener() {
    final Dialog setdatedialog = new Dialog(DropboxActivity.this);                      
    public void onClick(View v) {
    }
    public boolean onTouch(View arg0, MotionEvent arg1) {
    setdatedialog.setContentView(R.layout.datedialog);
    setdatedialog.setTitle("select date of puchase");
    setdatedialog.setCancelable(true);
    setdatedialog.show();
    Button back = (Button)setdatedialog.findViewById(R.id.back3);
    back.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
    setdatedialog.dismiss();
    }
    });
    Button setdate=(Button)setdatedialog.findViewById(R.id.setdate);
    DatePicker date = (DatePicker)setdatedialog.findViewById(R.id.datePicker1);                         
    class MyOnDateChangedListener implements OnDateChangedListener {
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth){
            et4.setText( "" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + year );
    }
    };
    date.init( year, monthOfYear, dayOfMonth, new MyOnDateChangedListener() );

    return false;
    }
  • 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-07T04:07:01+00:00Added an answer on June 7, 2026 at 4:07 am

    Define editText and Button in xml and below code in your activity:

            editText=(EditText) findViewById(R.id.date);
            button=(Button) findViewById(R.id.play);
            button.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    showDialog(DATE_DIALOG_ID);
                }
            });
    
            Calendar c=Calendar.getInstance();
            mYear=c.get(Calendar.YEAR);
            mMonth=c.get(Calendar.MONTH);
            mDay=c.get(Calendar.DAY_OF_MONTH);
    

    Now add these two functions to call DatePicker Dialog and to set date in the Edittext

    protected Dialog onCreateDialog(int id) {
            switch (id) {
            case DATE_DIALOG_ID:
                return new DatePickerDialog(this,
                            mDateSetListener,
                            mYear, mMonth, mDay);
    
            }
    
            return null;
    
        }
        private DatePickerDialog.OnDateSetListener mDateSetListener =new DatePickerDialog.OnDateSetListener() {
    
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                mYear = year;
                mMonth = monthOfYear;
                mDay = dayOfMonth;
                editText.setText(new StringBuilder().append(mDay).append("/").append(mMonth+1).append("/").append(mYear));
    
            }
    
        };
    

    Define this globally:

        static final int DATE_DIALOG_ID = 0;
        private int mYear,mMonth,mDay;
    

    This will help you to set date in the editText.Hope this will help you.

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

Sidebar

Related Questions

I have an edit text which functions as a search box in my application.
I have a program which has a text box that the user can edit.
In my application, in an activity i have 4 edit Text fields and a
I have an application that allows the user to edit multiple text fields and
i have to make a notepad where i write,edit,clear the text. this notepad need
I have a text file that I want to edit by rewriting it to
I have a text file that I want to edit using Java. It has
I have an Activity with an AutoComplete box on it. Whenever the text changes,
I have a drop-down list box and two text fields of id values namely
I've ran into next mystic thing in Winapi/MFC, I have an edit box, contents

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.