Is it possible that when click edittext it will show dialog message?

For the Same thing i have used :

 sel_date.setClickable(true);
 sel_date.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DEFAULTDATESELECTOR_ID);
        }
    });

And for setting Selected Date as EditText's Value :

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());
            }
    };

I have edited the code from Custom Date Picker in Android : http://blog.codeus.net/dateslider-1-0-an-alternative-datepicker-for-android/

You can replace Button with EditText and do the same as above code.

The keyboard seems to pop up when the EditText gains focus. To prevent this, set focusable to false:

<EditText
    ...
    android:focusable="false"
    ... />

Edited

Check The Following 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();
    }
};

}

Use this:

mDateDisplay.setClickable(true);
mDateDisplay.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        showDialog(DATE_DIALOG_ID);
    }
});

Alternatively, you can use the android:onClick attribute in the XML to point to a click-handling function in your Activity subclass.

(These days, of course, when pretty much everyone uses the compatibility libraries, you would probably want to create and show a dialog fragment rather than calling showDialog(), but the idea is the same.)


You can use OnClickListener event to handle the dialog box but after disabling the android:focusableInTouchMode of EditText in the xml file like this. eg - android:focusableInTouchMode="false".

Because when the EditText is first touched it calls the focus event and on second touch it call the click event so you have to disable the focus event first.