Situation
Need to present text files as a list of editable sentences or phrases as shown in the example below, for the purpose of a speech therapy tool. This was relatively easy.
The colored flags can be added, removed, or dragged to new positions as needed, and can be set to snap-to-character or snap-to-word (they will also eventually display data).
This was achieved by sub-classing EditText
, to take advantage of all the in-built features like word-wrapping, spell-checking, text-selection etc.
Problem
The number of phrases or sentences in a document can be large, so using a simple LinearLayout
in a ScrollView
to display them is no good in this case.
To efficiently display my FlaggedEditText
widgets the solution needs to take advantage of view recycling, so ListView
is an obvious consideration. But as shown by the number of S.O. questions out there, ListView
and EditText
don't play nice together.
The requirements of the list are that:
FlaggedEditText
widgets get focused when touched (the item containing theFlaggedEditText
also gets selected).- Notification when an item in the list has been edited (including which item).
- Standard gestures such as fling.
I've tried out numerous approaches suggested in the many S.O. questions over the past few days, to try and bend ListView to my requirements, but all seem to have their own short comings and result in hacky, messy code.
Questions
- Does anyone know of any existing alternatives to the standard Android
ListView
out there, that are moreEditText
friendly? - Alternatively, does anyone have a clean, efficient, definitive approach to getting
EditText
working as desired in the standardListView
? - Finally, I'm considering sub-classing
AdapterView
to make my ownFlaggedEditText
specificListView
alternative. But if the issues stem fromAdapterView
of whichListView
is also an indirect subclass, then I'd be wasting my time. Has anyone already been down this path?
Edit
Jim's excellent response below, and a recent viewing of Romain Guy and Adam Powell's old Google I/O 2010 presentation The world of ListView have suggested a possible solution.
In the I/O talk I was reminded that they convert views to bitmaps for some of their optimizations. Since only one EditText
at a time can ever be focused for editing, I'm thinking I can sub-class ListView
to provide an interface which, if ChoiceMode is single, will give the Rect of the selected Item and bitmaps of the ListView
regions above and below the selected item. This could then be used to temporarily overlay the ListView
with a vertical LinearLayout
containing the "above" bitmap, an active FlaggedEditText
and the "below" bitmap.
In this way, the FlaggedEditText
widgets can effectively act as non-focusable EditText
's in the ListView
, but when an Item is selected, interaction is with the temporary overlay.
The "above" and "below" bitmaps could also easily be tinted to suggest inactivity.
Additional
In fact, I've just realized I probably don't even need the Rect of the selected Item from the interface. The "above" and "below" bitmaps and a FlaggedEditText
using the same LayoutParams
as per the ListView
should be enough.