William Shapir
William Shapir

Reputation: 11

Library project and resources

I have developed an Android library project that contains all the common code and resources need to 2 other projects. The problem is that in a class of common library I need to load a different resource if it is used on project A or project B, respectively.

If I type R.string.myId it doesn't find the resource because it isn't on CommonLib, but it is defined on projects A and B.

How I can resolve this problem? What is the right way to obtain a kind of 'polymorphism' on this type of projects? Maybe I put in common library a code such as

 if  (ctx.getPackageName().equals("packageName A")
 else if (ctx.getPackageName().equals("packageName B"))

Thanks in advance.

Upvotes: 1

Views: 300

Answers (1)

Michael
Michael

Reputation: 54705

You can add some kind of stub resource to your library project and "override" them in application projects. Or you can add default values for resources to your library project and add some of this resources to application projects if necessary.

Upvotes: 1

Related Questions