user790156 user790156 - 2 months ago 11
Android Question

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

I want to click a edittext and show dialog date so I try

mDateDisplay = (EditText) findViewById(R.id.dateDisplay);
mDateDisplay.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
showDialog(DATE_DIALOG_ID);
}
}
});


The dialog will show if mDateDisplay is a button

but I want to use edittext

what should I do?

Answer

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.