I am building android projects with another project as a library. In the library project, it handles all creation method, the other projects refer to that library contains their own resources, like images.
There is a imageView in the library project, what I want to do is to pass the image to the library project to render it, however, I can't just pass the id because two projects have their own resources. I tried to make a Drawable in the child project, and pass to the parent project, it turns out nullpointerexception.
What I can think of is to pass bitmap, but don't know how to create a bitmap using images in the project folder, because all resources are compressed, and I can only use
context.getResources()
to retrieve the resource files.
Or are there some other ways to do this?
Updates:
Sorry guys, the NullPointerException is because I tried to use imageview before it calls
super.onCreate();
Now it throws no exceptions and can be run, but the imageview still can't display the image. My code:
ImageView imageview = (ImageView) findViewById(library.R.id.imageView1);
imageview.setImageResource(R.drawable.image);
Solution
It turns out that I tried to use imageview in the parent class before calling
super.onCreate()
and the image doesn't load because I
setContentView()
which covers the parent Activity's layout.
You can use the methods provided below to pass bitmap, or drawable to the imageview in the super class,
or create an imageview in the child class, then use the libraryPath.R to get the imageview in the parent class.