I am trying to build an Android input control which allows the user to construct a paragraph of text by bolting together different set phrases, and subsequently editing them. For instance, the following set phrases might be pre-defined:
- proceed miles
- north
- south
- look up
- start digging for treasure
- dig down metres below ground level
More than one phrase will be needed to construct a paragraph that makes sense. Furthermore, the phrases themselves, once entered, will need to be editable: for instance, in the first set phrase, a number will have to be inserted between “proceed” and “miles”. Here is an example of a paragraph that might conceivable be contructed with the help of such phrases:
Proceed 42 miles north, look up to the skies, then proceed 21 miles south. Start digging for treasure, and dig down 3 metres below ground level.
So far I’ve tried two main ways to accomplish this:
-
I tried adding a context menu to the
EditText, brought up by a long-press. The context menu’s entries each corresponded to a set phrase. Unfortunately, the build-in Android long press menu took over (cut/copy/paste options), thus preventing my context menu from ever being seen. -
I tried using a
MultiAutoCompleteTextViewwith aCommaTokenizer, loading the phrases from a resource file. This seemed promising, but it forces a comma after each phrase. Furthermore, it becomes pretty user-unfriendly to edit – backspacing the comma deletes the entire inserted phrase. I suppose constructing an entirely new Tokenizer is a possibility, but I don’t see what token I could actually use, nor how to prevent the deletion of the entire token when backspace is tapped. -
I took a different approach and looked at the Android user dictionary, to see whether I could add phrases in that. Unfortunately it seems it won’t accept phrases with spaces in them.
Has anyone any advice as to what I could try next?
Thanks.
I solved this by subclassing
MultiAutoCompleteTextViewand overriding thereplaceText()method to not “mark as replaced” the entered phrase. Works fine.