Monstieur
Monstieur

Reputation: 8112

How does ${packageName}.${activityClass} work in layout XML files?

ADT now generates XML layouts with the following attributes:

<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"
    tools:context="${packageName}.${activityClass}" >

How do the design tools know which class it belongs to?

Upvotes: 6

Views: 3461

Answers (3)

Jai Kumar Luhana
Jai Kumar Luhana

Reputation: 1

tools:context="${relativePackage}.${activityClass}"

realtivePackage and activityclass in there tags comes error how to solve

Upvotes: 0

openmic
openmic

Reputation: 83

My Eclipse ADT autogenerates the following:

<RelativeLayout 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"
    tools:context="${relativePackage}.${activityClass}" >

</RelativeLayout>

My question is: "Is there an Eclipse ADT reference that lists and explains all of the available variables one can use with the Android Tools Attributes?"

For example, it would be nice to see something like:

  • relativePackage: resolves to the value of the package= attribute of the <manifest> element in the file "AndroidManifest.xml".
  • activityClass: resolves to the value of the android:name= attribute of the <activity> element in the file "AndroidManifest.xml".
  • etc. ...
  • ... with a list of any/all other variables available for use

I found some links related to the tools namespace, but none of them explain how Eclipse ADT resolves, for example, ${relativePackage}.

Android Tools Project Site

Tools Attributes -> shows the attributes available in the "tools" namespace

Designtime Layout Attributes -> shows some of the "how and why" you would use the attributes

StackOverflow Site

Android “tools” namespace in layout xml documentation -> shows abstraction of the attributes values into xml files

What's “tools:context” in Android layout files? -> shows a lot of good info on Tools Attributes, but gives no answer to my question "Is there an Eclipse ADT reference that lists ..."; it only shows tools:context=".MainActivity"

What's tools:layout in fragment xml file? -> gives a bit of insight into using Eclipse ADT Graphical Layout editor

Upvotes: 1

Ramakishna Balla
Ramakishna Balla

Reputation: 1020

I don't know whether I got your question right but as far as I understood...it is about how does the ADT tool know that which package and which class...

The answer is at the time of creating the project, you might have mentioned (in general everybody does the same in most of the cases) the package name as well as the main activity class and from there the ADT tool picks up the details and puts them in the XML you referred...

Upvotes: 0

Related Questions