views:

514

answers:

1

Hi, 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  A: 

Popping a dialog when an EditText gets focus seems like a non-standard interface. Consider that the normal function of EditText is completely circumvented since you wouldn't even be able to make changes to a date that you chose because each time you give it focus you are popping this dialog.

Since you are using it as a TextView, why not just use an actual TextView coupled with a button? When the button is clicked, bring up the DatePicker and call TextView.setText() with the date formatted the way you want it. You can use the onClickListener for the button and it will behave as you expect. I believe this will make the function clearer to users.

RickNotFred