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
The keyboard seems to pop up when the EditText gains focus. To prevent this, set focusable to 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:
Once you've done this, your on click listener should work as desired:
This Works For me:
Nice topic. Well, I have done so. In XML file:
In Java-code:
As Dillon Kearns suggested, setting focusable to false works fine. But if your goal is to cancel the keyboard when EditText is clicked, you might want to use:
The following works perfectly for me.
First set your date picker widget's input to 'none' to prevent the soft keyboard from popping up:
Then add these event listeners to show the dialog containing the date picker:
One last thing. To make sure typed days, months, or years are correctly copied from the date picker, call
datePicker.clearFocus()
before retrieving the values, for instance viagetMonth()
.I had this same problem. The code is fine but make sure you change the focusable value of the EditText to false.
I hope this helps anyone who has had a similar problem!