Android EditText onClickListener


Question

i want an EditText which creates a DatePicker when is pressed. So i write the next code:

    mEditInit = (EditText) findViewById(R.id.date_init);
    mEditInit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DATEINIT_DIALOG);
        }

    });

But when i press the EditText the action is the typical: a cursor waiting for typing text instead show the Dialog i want.

Any idea?

Thanks

1
75
3/1/2010 9:26:03 PM

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

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

This behavior can vary on different manufacturers' Android OS flavors, but on the devices I've tested I have found this to to be sufficient. If the keyboard still pops up, using hints instead of text seems to help as well:

myEditText.setText("My text");    // instead of this...
myEditText.setHint("My text");    // try this

Once you've done this, your on click listener should work as desired:

myEditText.setOnClickListener(new OnClickListener() {...});
120
5/15/2011 5:00:54 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon