0

I have a next problem: I want to get a library based on android project and to use it in another project as 'external' library

  1. Is it possible?

  2. If it is possible - my MainProblem: how can I add resources into library? The way Project Properties -> Android -> "As Library" adds only .class-files!

MySituation:

public class ClassForLibrary extends Activity{ onCreate(){ setContentView(R.layout.library_activity_layout); } method1(){ } method2(){ } } 

So, I want to have a library with two files: ClassForLibrary.class and library_activity_layout.xml

Next I want to add this library using Build Path...

and start application as

public class MainActivity extends ClassForLibrary { . . . . . . . . . . } 

I've tried a lot of code constructions but the most closest situation is

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001. 

#0x7f030001 is my library_activity_layout.xml that i put manually into created library.

Сan anybody help me?

1 Answer 1

1

You can't access private library files in another application, unless the library itself exposes them. In your case, your library would need to create a function that lets the application replace the layout with it's own. Something like:

public class ClassForLibrary extends Activity{ onCreate(){ setContentView(R.layout.library_activity_layout); } public overrideContentView(ViewGroup root){ .... replace root view with the one passed in.... } method1(){ } method2(){ } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Hey! You peeped my code! )) That's what I'm doing (ok, a little more complicated). The problem was in overrided setContentView() when I wanted to inflate unexisted resource.
So, I'll try to create dynamic layout instead of static resource. Perhaps this is the only way. I'm really grateful to you advice. Thanx a lot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.