I have a text view with multiple lines of text e.g.
This is line 1
This is line 2
This is line 3
I want to be able to store the text depending on which line the user has clicked, i.e. if they click on line 2 I want to store “This is line 2”.
How can I go about this?
Edited 1 Sept:
I am not sure how the clickable span solution would work? I am able to get a specific line of text from my text view e.g. to get line 1 I would use:
TextView tv = (TextView) view.findViewById(R.id.class_list);
String selectedClass =(String)(tv).getText();
int l1start = tv.getLayout().getLineStart(1);
int l1end = tv.getLayout().getLineEnd(1);
String l1 = selectedClass.substring(l1start, l1end);
But I can’t see how to work out which line number has actually been clicked by using clickable span?
You can use a clickable span . Set a different span for each line and When clicked onClick method for this clickable span will be called.