Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For the Same thing i have used :</p> <pre><code> sel_date.setClickable(true); sel_date.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub showDialog(DEFAULTDATESELECTOR_ID); } }); </code></pre> <p>And for setting Selected Date as EditText's Value :</p> <pre><code>private DateSlider.OnDateSetListener mDateSetListener = new DateSlider.OnDateSetListener() { public void onDateSet(DateSlider view, Calendar selectedDate) { // update the dateText view with the corresponding date sel_date.setText(String.format("%te-%tB-%tY", selectedDate, selectedDate, selectedDate).trim()); } }; </code></pre> <p>I have edited the code from Custom Date Picker in Android : <a href="http://blog.codeus.net/dateslider-1-0-an-alternative-datepicker-for-android/" rel="noreferrer">http://blog.codeus.net/dateslider-1-0-an-alternative-datepicker-for-android/</a></p> <p>You can replace Button with EditText and do the same as above code.</p> <p>The keyboard seems to pop up when the <code>EditText</code> gains focus. To prevent this, set focusable to false:</p> <pre><code>&lt;EditText ... android:focusable="false" ... /&gt; </code></pre> <p><strong>Edited</strong> </p> <p>Check The Following code :</p> <pre><code>public class Main extends Activity { EditText et1,et2; static final int DATE_DIALOG_ID = 0; static final int DATE_DIALOG_ID1 = 1; private int mYear; private int mMonth; private int mDay; private int mYear1; private int mMonth1; private int mDay1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); et1=(EditText)findViewById(R.id.EditText01); et2=(EditText)findViewById(R.id.EditText02); final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); et1.setText("month/year"); et2.setText("month/year"); et1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub showDialog(DATE_DIALOG_ID); return false; } }); et2.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub showDialog(DATE_DIALOG_ID1); return false; } }); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); case DATE_DIALOG_ID1: return new DatePickerDialog(this, mDateSetListener1, mYear1, mMonth1, mDay1); } return null; } // updates the date in the TextView private void updateDisplay() { et1.setText(new StringBuilder() // Month is 0 based so add 1 .append(mMonth + 1).append("-").append(mYear)); } private void updateDisplay1() { et2.setText(new StringBuilder() // Month is 0 based so add 1 .append(mMonth1 + 1).append("-").append(mYear1)); } // the callback received when the user "sets" the date in the dialog private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; updateDisplay(); } }; private DatePickerDialog.OnDateSetListener mDateSetListener1 = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year1, int monthOfYear1, int dayOfMonth1) { // TODO Auto-generated method stub mYear1 = year1; mMonth1 = monthOfYear1; mDay1 = dayOfMonth1; updateDisplay1(); } }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload