Text selection listener in Android(API level 7)

后端 未结 2 631
终归单人心
终归单人心 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: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.

提交回复
热议问题