This code will help you to solve your problem..
It will pop-open a DatePicker dialogue box when onClick EditText box:
1) MainActivity.java
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.icu.text.DateFormat;
import android.icu.util.Calendar;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity
{
EditText editText1;
private int nYear,nMonth,nDay,sYear,sMonth,sDay;
static final int DATE_ID = 0;
Calendar c = Calendar.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1 = (EditText) findViewById(R.id.editText1);
sYear = c.get(Calendar.YEAR);
sMonth = c.get(Calendar.MONTH);
sDay = c.get(Calendar.DAY_OF_MONTH);
//editText
editText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDialog(DATE_ID);
}
});
/***************calender code*****************/
private void calender_fetch()
{
editText1.setText((nMonth+1)+"/"+nDay+"/"+nYear+"");
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
nYear = year;
nMonth = monthOfYear;
nDay = dayOfMonth;
calender_fetch();
}
};
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case DATE_ID:
return new DatePickerDialog(this, mDateSetListener, sYear, sMonth, sDay);
}
return null;
}
/*************************calender close*********************************/