0

In Droidio (Android Studio) at least (I don't know about Eclipse, but it's probably the case with ItelliJ Idea, too, as Droidio is based on it), when you create a new Activity, a corresponding Layout file is also created. By default, it is tightly coupled to the Activity by means of two properties, namely the "xmlns:tools" and "tools:context" lines below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="4dip"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hhs.app.PlatypusActivity">

This seems odd/unnecessary to me, as the Activity is also automagically bound to the corresponding Layout in the onCreate() method of its *.java file this way:

setContentView(R.layout.activity_platypus);

Is this a case of simply being "thorough" (wearing belts and suspenders), or is it a case of too-tight coupling? The explicit wiring on the Layout side (to the Controller/Activity) has a bit of a code smell to me. If I remove the two questionable lines from the xml ( "xmlns:tools" and "tools:context") it still works fine, so I don't understand what purpose they serve.

Will I live to rue the millisecond I semi-decoupled the Activity/Layout (Controller/View)?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Out of curiousity, why do you always call it Droidio? – Scott Barta Jun 03 '14 at 17:58
  • 1
    possible duplicate of [What's "tools:context" in Android layout files?](http://stackoverflow.com/questions/11078487/whats-toolscontext-in-android-layout-files) – Scott Barta Jun 03 '14 at 18:05
  • It's just short for anDROID studIO; I would rather say that than the whole blasted thing, which sounds squarer than all get out; and it reminds me of the cat in "Blackboard Jungle" that the students called "Daddy-O" (Didier). – B. Clay Shannon-B. Crow Raven Jun 03 '14 at 18:11

0 Answers0