Text selection listener in Android(API level 7)

后端 未结 2 620
终归单人心
终归单人心 2020-12-22 10:52

I need a listener which is called every time the selection in an EditText changes. I googled around but I couldn\'t find anything useful for API level 7. I\'m writing a Text

相关标签:
2条回答
  • 2020-12-22 11:16

    The better way to do it would be to extend the EditText and then based upon how you would want to manage the changing text, you could override one of the 2 methods to work out your customized behavior.

    1. If you want the selection changed then you could use the onSelectionChanged() method and implement your code there.

    2. In case you want to implement something when the text changes in your editor then you could use, onTextChanged().

    0 讨论(0)
  • 2020-12-22 11:21

    Pretty old question, but someone might still need this, so here's my solution : since the text selection accomplished with long press on the text, I simply used the following :

    editText.setOnLongClickListener(new View.OnLongClickListener() {
    
    @Override
    public boolean onLongClick(View view) {
            // do whatever you need to do on text selection
        }
    });
    

    This allows for custom behavior on text selection and doesn't prevent the user from copying/pasting.

    0 讨论(0)
提交回复
热议问题