Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnClick event only works second time on edittext

Tags:

android

I have an edittext, and when the user clicks this edittext I want to show an alertdialog.
My code is the following :

            edt.setInputType(InputType.TYPE_NULL);             edt.setFocusableInTouchMode(true);             edt.requestFocus();              edt.setCursorVisible(false);              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?

like image 471
Robby Smet Avatar asked Sep 24 '12 07:09

Robby Smet


1 Answers

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.

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

Now, it should works.

like image 138
Simon Dorociak Avatar answered Sep 28 '22 18:09

Simon Dorociak