Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid assign a drawable dynamicaly to a imageview
    primarykey
    data
    text
    <p>I have an array of drawables, that I would like to change by my own timer to a imageview. (i tried the other option with xml and setBackgroundResource, but does not work for me as I have hundret of pics and always got memory problem as it looks android assign already the whole memory for all pics at once. (just in this demo i shorted it to 4 images)</p> <p>Ok, so first i make my array</p> <pre><code>private static int[] draws = { R.drawable.frankiearmevor_0001, R.drawable.frankiearmevor_0002, R.drawable.frankiearmevor_0003, R.drawable.frankiearmevor_0002 }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imgView = (ImageView) findViewById(R.id.fredi); // create timer Timer updateProgressTimer = new Timer(); updateProgressTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { myloop(); } }, 0, 150); } int mycounter; public void myloop() { mycounter++; if (mycounter &gt; 4) mycounter = 1; imgView.setImageResource(draws[mycounter-1]); String hallo; hallo = "now: "+mycounter; Log.d("1",hallo); } </code></pre> <p>when I assign only a fixed image: imgView.setImageResource(draws[2]); it shows that fine and I see also my thread is logged fine, but when I exchange the fixed resource draws[2] into a dynamic draws[mycounter-1] .. i just get a black screen, no error, nothing.</p> <p>what to do, so i will show the images :)</p> <p>thx chris</p> <p>EDIT: 22. August:</p> <p>I tried now with the comment I got, it compiles fine, but somehow there is an error i guess.. it crash:</p> <pre><code> imgView = (ImageView) findViewById(R.id.fredi); Timer updateProgressTimer = new Timer(); updateProgressTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { //myloop(); imgView.post (new Runnable() { public void run() { mycounter++; if (mycounter &gt; 10) mycounter = 1; imgView.setImageResource(draws[1]); //imgView.invalidate(); String hallo; hallo = "now: "+mycounter; Log.d("1",hallo); } }); } }, 0, 150); </code></pre>
    singulars
    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.
 

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