OnClick事件只能第二次的EditText [英] OnClick event only works second time on edittext

查看:154
本文介绍了OnClick事件只能第二次的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EditText,当用户点击这个的EditText我想表现出alertdialog。
我的code是如下:

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());
                }
            });

我不想键盘显示当用户点击的EditText,所以我设置inputtype为TYPE_NULL。
但是,当EditText上没有焦点,我点击它,不执行onclick事件。当我点击它第二次,alertdialog显示正确。

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?

推荐答案

只是一味把它添加到您的 XML 文件。您的键盘弹出当小工具获得焦点。 因此,要prevent这种行为设置可聚焦到。然后正常使用 OnClickListener

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"
  ...
/>

现在,它应该工作。

这篇关于OnClick事件只能第二次的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆