How can I get text( word ) in TextView by knowing x, y coordinates of my click on screen? Thanks.
Asked
Active
Viewed 1,329 times
2
-
1What does your research says? Have you googled it? This has already been asked by users, for example [this post](http://stackoverflow.com/questions/8616064/touch-coordinates-in-textview) – Adil Soomro Apr 03 '12 at 11:50
-
I cant find anythink, thats way I'm asking – Lang Apr 03 '12 at 12:49
1 Answers
0
check the following code.. its working fine with me,
public class ProjjActivity extends Activity {
TextView txtview;
float X,Y;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtview = (TextView) findViewById(R.id.tt);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
X = event.getX();
Y = event.getY();
txtview.setText("X: "+X+", Y: "+Y);
return super.onTouchEvent(event);
}
}
hope this helps you..!

Nirav Dangi
- 3,607
- 4
- 49
- 60
-
Cool, but OP (Owner of the Post) is asking about, touching the `TextView` and get Text from `TextView`. – Adil Soomro Apr 03 '12 at 12:08
-
@AdilSoomro It seems bit confusing to me but if he is asking like that then its so simple. Just need to put "txtview.getText()" in click event of that textview, it will return string. – Nirav Dangi Apr 03 '12 at 12:19
-
Yea that is simple, but OP wants the text of nearby area, where he touches, not the full text. – Adil Soomro Apr 03 '12 at 12:34