Robby Smet Robby Smet - 8 months ago 82
Android Question

OnClick event only works second time on edittext

I have an edittext, and when the user clicks this edittext I want to show an alertdialog.

My code is the following :



edt.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
CommentDialog.buildDialog(mContext, identifier, false, edt.getId());

I don't want the keyboard to show up when the user clicks the edittext, so I set the inputtype to TYPE_NULL.

But when the edittext doesn't have focus and I click it, the onClick event isn't executed. When I click it a second time, the alertdialog shows up correctly.

How do I fix this?


Simply try to add this to your XML file. Your keyboard pops up when widget gains focus. So to prevent this behaviour set focusable to false. Then normal use OnClickListener.


Now, it should works.