Reputation: 363
I Would like to solve this problem.
I have a Layout which only contains an ImageView, it looks like this:
Presentation_i.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:id="@+id/layoutiz">
<ImageView
android:id="@+id/IMpresIZ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I want to add a background image to this ImageView, but I want to do it from an activity which doesn't use this xml.
How can I assing a background image for an ImageView, which is NOT in the xml that i'm using in the activity.
I tryed it with Inflate, but can't make it work.
I would really appreciate a sample code, since i've been struggling a few days to make it work.
Thank you very much in advance,
Best Regards,
Thank you for all answers. The problem is that the ImageView is inside a xml which I use for a ViewPager. That xml is not called from any activity. That's why I can't apply those solutions, becouse there is no activity related to the xml. The point of this thing is to display the background of the ImageView from an image previously downloaded from internet. Thank you very much for your interest. Best regards.
Upvotes: 1
Views: 733
Reputation: 30825
So it sounds like you're trying to do inter-actvitiy communication. You basically want what happens in one activity to affect the other. This can be accomplished in a few ways. I'll highlight two of them that I think would be most appropriate for you.
You should use shared preferences. Store the selection of the background image from the first activity and then when you start the other activity, just look at the shared preferences to see which image to load.
If the activity that picks the image is displayed before the activity that actually has the background image, then you can just pass the image that should be used along with the intent you use to start that second activity.
Upvotes: 1