Reputation: 11
Here's my XML :
<ImageView android:id="@+id/IVtarih1"
android:layout_height="125dp"
android:layout_width="125dp" />
And my Activity
ImageView image1 = (ImageView) findViewById(R.id.IV1);
new DownloadImageTask(image1).execute(urlStr1);
ImageView iv = (ImageView) findViewById(R.id.IV2)
iv.setImageResource(R.id.image1);//I can't find id of image1
I'm getting the background of image1 from an url. So i don't have any drawable. I want to set background of image1 to ImageView iv. How can I do this? I thought that if I find the id of image1 I can achive this. The id of image1 is changing every runtime.
Upvotes: 0
Views: 804
Reputation: 30168
You seem to be confused. You don't need the ImageView's id for that. You just need to do imgView.setImageResource(R.drawable.drawable_name)
.
Upvotes: 0
Reputation: 963
Set the id in the XML ahead of time like
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Then in your Activity you can get it by
ImageView myImage = (ImageView)findViewById(R.id.myImageView);
Upvotes: 1