Android: How do I create reusable components?

2019-07-13 10:00发布

问题:

I've spent a while scouring the net for some sort of information on this, but to no avail.

I'm working on an app for which I needed to create some components, some of which would be likely to have other applications, so I'd like to put them in their own package or project, but am not sure what the correct way to do this is.

So my main project is called something like...

<companyname>.<productname>

And I've called the package for my widgets...

<companyname>.widget

I created a separate project for the widgets and moved the relevant code, layout, resources etc over. That project seems to compile properly, but the main project no longer recognises any references to the widgets.

I added the new widget project to the main project's Project References, but that made no difference.

Any ideas or links to tutorial on how to do this correctly would be much appreciated.

回答1:

Have you tried setting up a library project?
https://developer.android.com/guide/developing/eclipse-adt.html