Android::Update Imagebackgorund at runtime
<p>I want to change the background color of an image according to the input text message.
Moreover, I want the background color can stay for a certain amount of time before it change to serve another input message.</p>

<p>For example,
   Assume the input message is "a", I first transfer it to "101010". Then i hope my program can show image as "white black white black white black" ,where white represent 1 and black represent 0, and each color can stay for a certain time (which i can decide).</p>

<p>The following is my code.</p>

<pre><code>    public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
}

public Runnable ChangeColor2White(ImageView im){
    //Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.black_im);
    //im.setImageBitmap(bmp);
    im.setBackgroundResource(R.drawable.white);

    return null;
 }

public Runnable ChangeColor2black(ImageView im){
    //Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.white_im);
    //im.setImageBitmap(bmp);

    im.setBackgroundResource(R.drawable.black);

    return null;
  }

 public void cvOnClick(View myView){
    EditText Input = (EditText) findViewById(R.id.myText1);
    String data = Input.getText().toString();
    char  dataArray[] = data.toCharArray();
    Vector&lt;Integer&gt; v = new Vector&lt;Integer&gt;();
    TextView Output = (TextView) findViewById(R.id.myText2);

    ImageView im = (ImageView) findViewById(R.id.myImage1);

    Handler handler = new Handler();

    for(int i=0;i&lt;data.length();i++){
        int temp = (int)dataArray[i];int par1,par2,par3,par4,par5,par6 = 0;

        if(temp!=97){
            if(temp&gt;=48 &amp;&amp; temp&lt;=57)                  //0~10 (0~9)
                temp-=48;
            else if(temp&gt;=65 &amp;&amp; temp&lt;=90)             //A~Z  (10~35)
                temp-=55;
            else if(temp&gt;=98 &amp;&amp; temp&lt;=122)            //a~z  (36~61)
                temp-=61;
            else
                temp =62;           

            par1 = temp/32;
            if(par1&gt;0){
                par1 = 1;temp-=32;}
            par2 = temp/16;
            if(par2&gt;0){
                par2 = 1;temp-=16;}
            par3 = temp/8;
            if(par3&gt;0){
                par3 = 1;temp-=8;}
            par4 = temp/4;
            if(par4&gt;0){
                par4 = 1;temp-=4;}
            par5 = temp/2;
            if(par5&gt;0){
                par5 = 1;temp-=2;}
            par6 = temp/1;
            if(par6&gt;0){
                par6 = 1;temp-=1;}

            v.addElement(par1);
            v.addElement(par2);
            v.addElement(par3);
            v.addElement(par4);
            v.addElement(par5);
            v.addElement(par6);
        }
            else if(temp==97){
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
            }
        }

    Output.setText(v.toString());

    for(int i=0;i&lt;v.size();i++){

        if(v.elementAt(i)==0){
            //handler.removeCallbacks(ChangeColor2black(im));
            //handler.postDelayed(ChangeColor2black(im), 1000);
            ChangeColor2black(im);

        }

        else if(v.elementAt(i)==1){
            //handler.removeCallbacks(ChangeColor2White(im));
            //handler.postDelayed(ChangeColor2White(im), 1000);
            ChangeColor2White(im);
        }

        try{
            Thread.sleep(1000);
        }
        catch(InterruptedException e){
            e.printStackTrace();
        }
    }
 }
 }
</code></pre>

<p>My problem is that the program only show me the result of the last bit which means that the background remain default till the program ended and it show me the result of the last input bit.
I also tried handler instead of Thread.sleep(). But it is the same story all over again.
Let's me show you the code</p>

<pre><code>     public void cvOnClick(View myView){
    EditText Input = (EditText) findViewById(R.id.myText1);
    String data = Input.getText().toString();
    char  dataArray[] = data.toCharArray();
    Vector&lt;Integer&gt; v = new Vector&lt;Integer&gt;();
    TextView Output = (TextView) findViewById(R.id.myText2);

    final ImageView im = (ImageView) findViewById(R.id.myImage1);

    Handler handler = new Handler();

    for(int i=0;i&lt;data.length();i++){
        int temp = (int)dataArray[i];int par1,par2,par3,par4,par5,par6 = 0;

        if(temp!=97){
            if(temp&gt;=48 &amp;&amp; temp&lt;=57)                  //0~10 (0~9)
                temp-=48;
            else if(temp&gt;=65 &amp;&amp; temp&lt;=90)             //A~Z  (10~35)
                temp-=55;
            else if(temp&gt;=98 &amp;&amp; temp&lt;=122)            //a~z  (36~61)
                temp-=61;
            else
                temp =62;           

            par1 = temp/32;
            if(par1&gt;0){
                par1 = 1;temp-=32;}
            par2 = temp/16;
            if(par2&gt;0){
                par2 = 1;temp-=16;}
            par3 = temp/8;
            if(par3&gt;0){
                par3 = 1;temp-=8;}
            par4 = temp/4;
            if(par4&gt;0){
                par4 = 1;temp-=4;}
            par5 = temp/2;
            if(par5&gt;0){
                par5 = 1;temp-=2;}
            par6 = temp/1;
            if(par6&gt;0){
                par6 = 1;temp-=1;}

            v.addElement(par1);
            v.addElement(par2);
            v.addElement(par3);
            v.addElement(par4);
            v.addElement(par5);
            v.addElement(par6);
        }
            else if(temp==97){
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
                v.addElement(1);
            }
        }

    Output.setText(v.toString());

    for(int i=0;i&lt;v.size();i++){

        if(v.elementAt(i)==0){
            handler.removeCallbacks(ChangeColor2black(im));
            handler.postDelayed(new Runnable() {
                public void run() {
                    ChangeColor2black(im);
                }
            },1000);

        }

        else if(v.elementAt(i)==1){
            handler.removeCallbacks(ChangeColor2White(im));
            handler.postDelayed(new Runnable() {
                public void run() {
                    ChangeColor2White(im);
                }
            },1000);
        }
    }       
 }
}
</code></pre>

<p>And the result of my virtual Machine of Android:
<a href="http://i.imgur.com/QKWj6.png" rel="nofollow">http://i.imgur.com/QKWj6.png</a></p>

<p>(Notice that this image is the result of the program, so it is correct for the last bit 0 which represent by black background)
Thx in advance~</p>
