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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:44:03+00:00 2026-05-27T12:44:03+00:00

My XMl Layout is as like below: <RelativeLayout android:id=@+id/dateSelectionLayout android:layout_width=fill_parent android:layout_height=wrap_content android:orientation=vertical android:visibility=visible> <EditText

  • 0

My XMl Layout is as like below:

<RelativeLayout  android:id="@+id/dateSelectionLayout"  android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical" android:visibility="visible">

            <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" 
                android:singleLine="true" android:id="@+id/dateSelectionEditText" android:gravity="center"
                android:textColor="#000000" android:textSize="14sp" android:cursorVisible="false"
                android:focusable="false"
                android:hint="tax code" android:layout_weight="1"/>

            <DatePicker android:id="@+id/datePicker"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_weight="1" android:layout_below="@+id/dateSelectionEditText"/>

    </RelativeLayout>

Now i want to change the value of the editText that is based on the datePicker date. If User change the date then it should be reflected on the editText at that time. how it is Possible ?

Edited:
I have done like this:
Have set the resourcec like:

datePicker = (DatePicker) findViewById(R.id.datePicker);
        dateSelectionEditText = (EditText)findViewById(R.id.dateSelectionEditText);

And have set the override method like this:

@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
        int dayOfMonth) {
    dateSelectionEditText.setText(dayOfMonth+"/"+monthOfYear+"/"+year);

}

But still not getting any value on the changing of date picker value.

Edited:

After Kasper Moerch’s answer i got the solution. But there is little problem.
I am using this code to init the datepicker.

final Calendar c = Calendar.getInstance();  
        //dateSelectionEditText.setText( "" + dayOfMonth + "-" + monthOfYear + "-" + year );
        datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), new MyOnDateChangedListener());
        Toast.makeText(getApplicationContext(), ""+position+"", Toast.LENGTH_SHORT).show();

Now with this, I am able to see the changed value from datePicker. But it takes 0 as a First month (from January) instead of the “1”. So why it is happend like this ?

Thanks.

  • 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-05-27T12:44:04+00:00Added an answer on May 27, 2026 at 12:44 pm

    What you need to do is get a reference to the EditText and the DatePicker:

    EditText editText = (EditText) findViewById( R.id.dateSelectionEditText );
    DatePicker datePicker = (DatePicker) findViewById( R.id.datePicker );
    

    Then you need to create an OnDateChangedListener:

    private class MyOnDateChangedListener implements OnDateChangedListener {
      @Override
      public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
         editText.setText( "" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + year );
      }
    };
    

    All thats left to do is just initialize the DatePicker:

    datePicker.init( year, monthOfYear, dayOfMonth, new MyOnDateChangedListener() ).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did like below in xml <TableRow> <TextView android:id=@+id/address1 android:layout_width=fill_parent android:layout_height=wrap_content android:gravity=left android:maxLines=4 android:singleLine=false
In My Application, My XML layout is like this: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <View class=com.project.twsbi.FingerPaint$MyView
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have the following layout in my xml file: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <FrameLayout android:id=@+id/logoLayout
In my xml I have: <RelativeLayout android:id=@+id/mainWeek android:layout_height=387dip android:layout_width=match_parent android:layout_marginTop=5dip> <RelativeLayout android:id=@+id/day1 android:layout_marginTop=5dip android:layout_marginLeft=5dip
I have a layout like this: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical > <include layout=@layout/basicinfo
I want to create a layout like below.. This is the XML i have
I have a simple layout like below (which only shows a text TEST): <?xml
i was trying to layout views within RelativeLayout like this: <?xml version=1.0 encoding=utf-8?> <RelativeLayout
Why does my relative layout occupy full screen width <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

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.