title: How can i get a image resource from an URL
body: <p>I tried using the library &quot;<strong>Picasso</strong>&quot; but it needs a pre-created ImageView, and I am trying to put it in a new ImageView but when I put the id that the ImageView will have it gives me an error.</p>
  <p>I am using this code to create the ImageView:</p>
  <pre><code>    val photo  = ImageView(applicationContext)
  
      photo.id = variable1
                
      Scroll.addView(photo) 
  </code></pre>
  <p>And I am using this code to put the image:</p>
  <pre><code>Picasso.get().load(&quot;$url&quot;).into(variable1)
  </code></pre>
  <p>And this does not work, so I thought it will be a good idea to put the photo in a pre-created ImageView and then getting the image reference of that ImageView and giving it to the new ImageView as:</p>
  <pre><code>var photoResource = R.id.borramePerro.getResource()
  photo.setImageResource(photoResource)
  </code></pre>
  <p>But it doesn't work. Any ideas?</p>
  <pre><code>    class InicioSesionGoogle: AppCompatActivity() {
      
      
         override fun onCreate(savedInstanceState: Bundle?) {
  
           super.onCreate(savedInstanceState)
           setContentView(R.layout.google)}
  
          
         var urlImagen : String
  
         var variable1 = 1
         fun showPhoto(url: String){
              val photo  = ImageView(applicationContext)
              
              Picasso.get().load(&quot;$url&quot;).into(variable1)
  
              photo.id = variable1
              
              Scroll.addView(photo)
  
  
  
  
              
              println(&quot;Photo set :D   $url with the id of: $variable1&quot;)
              variable1++
  
             
          }
  </code></pre>
  <p><strong>Xml:</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:visibility=&quot;visible&quot;&gt;
  
      
  
      
  
      &lt;ScrollView
          android:id=&quot;@+id/ScrollVieww&quot;
          android:layout_width=&quot;310dp&quot;
          android:layout_height=&quot;204dp&quot;
          android:layout_marginTop=&quot;32dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
          &lt;LinearLayout
              android:id=&quot;@+id/Scroll&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              android:orientation=&quot;vertical&quot; /&gt;
      &lt;/ScrollView&gt;
  
      
      &lt;ImageView
          android:id=&quot;@+id/borramePerro&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          tools:srcCompat=&quot;@tools:sample/avatars&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>