如何确定何时选择文本[Android [EditText]] [英] How to determine when text is selected [Android [EditText]]

查看:166
本文介绍了如何确定何时选择文本[Android [EditText]]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定何时选择文本,何时不选择文本?

Is possible to determine when text is selected and when is not?

我正在使用Google搜索,并使用find onSelectionChanged()方法或setOnLongClickListener()来确定用户longClick何时编辑文本,以便他进行选择,但是在两种情况下,它都无法帮助我确定何时不使用该用户.选择任何文本(我可以将按钮设置为不可见)...

I was googling and I find onSelectionChanged() method or setOnLongClickListener() for determining when user longClicks the editText so when he made selection, but in both cases it can't help me with determining, when the user is not selecting any text (I could set button invisible)...

推荐答案

您可以使用

yourEditText.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            if (MotionEvent.ACTION_UP == event.getAction()) {

              if (yourEditText.hasSelection()) {
                // if true, the text in the EditText is selected
              }

            return false;
          }
        });


那应该做.


That should do it.

这篇关于如何确定何时选择文本[Android [EditText]]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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