开发者

Howto access the main res/layout/ files from a sub package?

开发者 https://www.devze.com 2023-03-08 06:43 出处:网络
This is also a design question. I don\'t know the best way to design having many activities and how to break them up into packages while still accessing the apps resources.

This is also a design question. I don't know the best way to design having many activities and how to break them up into packages while still accessing the apps resources.

I have an application which allows a user to login and access a tabbed activity which gives access to many modules. If they click a module they will load the module which will in turn contains a tabbed activity.

Currently i have 3 packages within this app:

  • com.appname.app (many activities i'd like to split up, login, module list etc)
  • com.appname.app.XML (xml handlers)
  • com.appname.app.Utils (static util classes etc)

I'd like to add a new package to contain all my modules so something like

  • com.appname.app.Modules ( or even a seperate package for EACH module)

But i can then no longer access the main apps resources without referring to them with a full package name such as setContentView(com.appname.app.R.layout.channel_list);

Obviously within any com.appname.app activities i just reference the resources such as layouts via setContentView(R.layout.channel_list);.

I'd have thought that a sub package (sub directory) should have access to a parent's resources without having to use com.appname.app.R.layout.channel_list instead of R.layout.channel_list. Which is why i'm assuming something is wrong with my design

The same issue goes for accessing string, drawable etc resources...

Im sure this is something very basic I'm missing. I've tried manually importing the "parent" package and that didn't work either.

is this how i should be d开发者_高级运维oing things? or should i somehow be creating the resource files within each module package? or there another way i should be handling the design/split up of my app?


Since the Android pre-compiler would compile all references to a R.class file and place in in the main package there's no better way than to explicitly import the resources wherever you want to use them

import com.appname.app.R;

so that no full qualifier is needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消