4

For my Android application, I would like there to be a sentence on the screen (a TextView or an EditText or something in that direction) which looks like this:

The red ___________ jumped over the lazy dog.

where the user can click on the underscore and complete the sentence themselves. I could accomplish this by having the entire sentence represented by an EditText, but I would like the Strings The red and jumped over the lazy dog. to be uneditable.

I have a lot of sentences like that which should be completed, so hardcoding the uneditable parts of the string as an image or something will not work. How do I do this?

Sid
  • 563
  • 1
  • 10
  • 28
  • You could place the editview in between the textviews. – Popeye Jul 30 '17 at 02:09
  • @Popeye How do I make sure that the TextViews and EditView are lined up correctly for sentences of various lengths and lines? – Sid Jul 30 '17 at 11:14
  • You can use dynamically draw like this https://stackoverflow.com/questions/19788386/set-unchangeable-some-part-of-edittext-android – Popeye Jul 30 '17 at 13:44
  • @Popeye Unfortunately that is not a useful solution since the sentences are of various lengths and can take multiple lines, so a solution like that is not going to be flexible enough. I am amazed how hard this simple task is for Android. – Sid Jul 30 '17 at 16:14
  • I still believe that relative layout would work, by keeping editviews in textviews whatever the number of lines in a paragraph. https://stackoverflow.com/q/11577570/4002680 – Popeye Jul 30 '17 at 16:34
  • @Sid did you find a solution? – Aashir Jul 14 '18 at 21:48
  • I ended up using the addTextChangedListener. It did not achieve exactly what I wanted, but close enough. – Sid Jul 14 '18 at 22:44
  • @Sid did you get any robust solution for this? – Shashank Srivastava Oct 16 '18 at 06:52
  • @ShashankSrivastava No, just a hack. – Sid Oct 17 '18 at 18:47

1 Answers1

0

Try to use addTextChangedListener. Using afterTextChanged you may control uneditable parts of text by change it back after editing.

Vasily Avilov
  • 147
  • 2
  • 11
  • This is perhaps a functioning solution but it's really bad design. I don't want the user to be able to change the uneditable parts of the sentence at all, no matter that the sentence is changed back later. – Sid Jul 30 '17 at 11:18