Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText onClickListener in Android

I want an EditText which creates a DatePicker when is pressed. So I write the following 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.

like image 243
Gerardo Avatar asked Mar 01 '10 21:03

Gerardo


1 Answers

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() {...}); 
like image 73
Dillon Kearns Avatar answered Sep 20 '22 23:09

Dillon Kearns