Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: using resources from another project in my workspace

I am fairly new to Android development - coming from a WPF background.

I have created two Android projects in my "workspace" in Eclipse. One is called "TestProject", and the other called "TestLibraryProject".

Inside of "TestLibraryProject" I have created a custom view called BlueBox.

I now want to use BlueBox in my main layout of "TestProject". Knowing that I needed to reference "TestLibraryProject" from "TestProject" somehow, I right-clicked on "TestProject" and followed the menu:

Build Path -> Add Libraries

In the dialog that popped up I selected "Android Classpath Container", and in the immediate dialog following that I chose "TestLibraryProject" from the combo-box.

Two-fold question: 1. Is this the correct way to include "TestLibraryProject" into "TestProject" so that I can use it? 2. How can I now use BlueBox in my main layout XML?

I tried simply putting this in into the XML file:

<mypackage.TestLibraryProject.BlueBox
        android:id="@+id/my_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

But that didn't work. I also tried referencing the namespace in my root layout element:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:binding="http://www.gueei.com/android-binding/"
    xmlns:testlibrary="http://schemas.android.com/apk/res/android/mypackage2.TestLibraryProject"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

But that didn't seem to help.

Any suggestions? Ideas? Help?

Thanks!

like image 280
David Avatar asked Dec 28 '22 11:12

David


1 Answers

To add a library project first make sure that your library project is actually marked as a library project.

Right click on the project node --> properties --> Android --> Is Library checkbox --> OK

Then in your main Android project:

Right click the project node --> properties --> Android --> Add --> Select your library project --> OK --> OK

like image 65
Damian Avatar answered Jan 15 '23 14:01

Damian