Note that there are some explanatory texts on larger screens.

plurals
  1. POImageview doesn't load the image programatically
    primarykey
    data
    text
    <p>I have a layout with a <code>ImageView</code> component I want to load a image programatically</p> <p>I tried to load a image from a file and from a drawable resource, in the <code>OnCreate()</code> event and when a button is pressed but no image is loaded and no error is thrown.</p> <p>I'm using <code>.Invalidate()</code> method too without results</p> <p>Example for drawable resource (<strong>Monodroid code</strong>)</p> <pre><code>ImageView ivStock = view.FindViewById&lt;ImageView&gt;(Resource.Id.IV01); </code></pre> <p>Way 1:</p> <pre><code>ivStock.SetImageResource(Resource.Drawable.Circle_Green); </code></pre> <p>Way 2:</p> <pre><code>ivStock.SetBackgroundResource(Resource.Drawable.Circle_Green); </code></pre> <p>Way 3:</p> <pre><code>ivStock.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.Circle_Green)); </code></pre> <p>and ever </p> <pre><code>ivStock.Invalidate(); </code></pre> <p>I tried to do that task in a <code>Thread</code> and in a Task. I think I'm missing something and I don't know what.</p> <p><strong>EDIT 1:</strong> I tried that in the same activity/layout and it works fine</p> <pre><code>btnOk.SetBackgroundDrawable(Resources.GetDrawable(Resource.Drawable.Circle_Green)); </code></pre> <p>Could it be a bug?</p> <p>Any help will be appreciated Thanks in advance</p> <h2><strong>SOLVED</strong></h2> <p>Sorry folks, I was defining my ivStock inside a <code>View</code></p> <pre><code>View view = LayoutInflater.Inflate(Resource.Layout.VisorImagenes, null, false); ImageView ivStock= view.FindViewById&lt;ImageView&gt;(Resource.Id.ImagenStock); </code></pre> <p>And I was doing anything with this view, so ivStock wasn't in the layout/activity ambit</p> <pre><code>ImageView ivStock= FindViewById&lt;ImageView&gt;(Resource.Id.ImagenStock); </code></pre> <p>Is the proper code</p> <p>Thanks all!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload