Android: using resources from another project in my workspace

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

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

Inside "TestLibraryProject" I created my own view called BlueBox.

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

Build Path → Add Libraries

In the dialog box that appears, I selected “Container for Android classes”, and in the next dialog box, I selected “TestLibraryProject” from the combo box.

Two questions: 1. Is it correct to include “TestLibraryProject” in “TestProject” so that I can use it? 2. How can I now use BlueBox in my main XML layout?

I tried just pasting this into an XML file:

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

But that did not 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 it did not help.

Any suggestions? Ideas? Help?

Thanks!

+4
source share
1 answer

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

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

Then in your main Android project:

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

+10
source

Source: https://habr.com/ru/post/1379714/


All Articles