I am using webview in one of my android projects(OS version 4.4+). Webview gives default functionality to select the text by "longpressing". But my project requirement is to select the text just by tapping on it and not by long pressing. I have tried methods mentioned in this link to achieve the functionality (Detect which word has been clicked on within a text). But it is not working for me. Can any one please guide how to achieve this task.
Asked
Active
Viewed 1,085 times
0
-
refer this link http://stackoverflow.com/questions/8034369/how-to-select-a-word-in-android-webview – Anjali Tripathi May 27 '15 at 13:59
-
2please provide the exact code you have tried and how it failed. – AKroell May 27 '15 at 13:59
-
this is the code
i tried. it is working fine in mozilla browswer but not on android tablet. It return empty string – Sumeet kumar May 27 '15 at 14:10 -
@AnjaliTripathi the link you mentioned says that you cannot achieve it. can you suggest some word arounds – Sumeet kumar May 27 '15 at 14:11
-
yes this right it is impossible. also refer another link http://stackoverflow.com/questions/9076113/android-highlight-a-word-phrase-in-a-webview – Anjali Tripathi May 27 '15 at 14:14
-
you can do one thing get data from server in string and show it in textview then select it. – Anjali Tripathi May 27 '15 at 14:15
1 Answers
1
By this below method, you can select text by clicking on it after 1 second without needing to hold it:
webView.setOnTouchListener(new View.OnTouchListener() {
Boolean tF;
@Override
public boolean onTouch(View v, MotionEvent event) {
tF = true;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
tF = false;
}
return tF;
}
});

M. Feyz
- 359
- 2
- 9