GeoffC
GeoffC

Reputation: 71

Multiple resources with the same id

Although I cannot find a specific reference I assume that you cannot give the same id to resources in two different activities. eg. myTextView in Activity 1 and myTextView (with nothing to link them) in Activity 2. If this is so, how is a ListView in a ListActivity, which has to be called "list", handled when you have two or more ListActivities?

Upvotes: 0

Views: 1509

Answers (1)

gprathour
gprathour

Reputation: 15333

The first thing I would like to tell you is, you can give id's in the XML files not in Activities. However we access those elements in activities via their ids.

You can have same id for two or more elements in different XML files

But you cannot give same id to two or more elements in same XML file

In your activity find out a line in the onCreate method,

setContentView(R.layout.YOUR_XML_FILE);

So whenever you will access any element with an id, it will search only in the above mentioned XML file, not in any other.

So as you will be having different XML files in different activities, so each activity will look for resource in its own XML file. It will have no effect on any other resource in any other XML file.

Upvotes: 3

Related Questions