Say I have two activities in an Android app, EditPerson and EditEmployee .
It would seem natural that EditPerson Activity is the base class for EditEmployee Activity and defines methods that marshal data in and out of the views defined in the layout. Operation EditPerson Actions will push (for example) the Name field to and from the EditText element. Versions of EditEmployee will invoke the base class version and then marshal their specialized fields (e.g. tax id, etc.).
To facilitate common code, both actions should have a layout resource that defines one or more pairs of EditText elements that have the same identifier. those. in layout\edit_person.xml would be:
<EditText android:id="@+id/name_editor" />
And then in layout\edit_employee.xml will be something like:
<EditText android:id="@+id/name_editor" /> <EditText android:id="@+id/tax_id_editor" />
Since the "Employee" is "Person", and there are common fields (marshaled through inheritance), it looks like the assigned id ("name_editor" in the above example) should be unique within the scope of the action (or layout?).
From my testing, this works, but I'm paranoid that there will be an unintended side effect of this approach and the use of ambiguous identifiers for layout elements. Can someone confirm that this is a safe practice and / or indicate how it will ultimately blow up my application? Has anyone ever done such things?
android inheritance layout view ambiguity
el2iot2
source share