开发者

Change Image on runtime

开发者 https://www.devze.com 2023-02-26 11:23 出处:网络
I am able to now change an image when pressing OnTouch, for example I press image1 make it invisible and show the one i have underneath it...

I am able to now change an image when pressing OnTouch, for example I press image1 make it invisible and show the one i have underneath it...

Now i want to change an image on runtime, basically I have an array if array[i] = 5; then i want to make image5 invisible?

How can I do this?, I tried it with a

try{
     Thread.sleep(2000);
     }
catch
  {
  }

and it blacks out the screen and then shows the backgroung after 2 seconds but i never see the image get invisible;

i would like to be able to do something like this

for(int i=0;i < array.length; i++)
{
 if(array[i] == 1)
     {
          try
          {
         Thread.sleep(1000);
         ImageView image = (ImageView)findById(myImage01);
         image.setVisibility(View.INVISIBLE);      
         Thread.sleep(1000);
         image.setVisibility(View.VISIBLE);  

           }  
         catch(InterruptedException e) 
            {
            }
       }

}

You get the id开发者_StackOverflowea... right now if i do this it will black out the screen and then return to the main layout and do nothing :(

Thank you in advance

By the way I am new in Android (please consider :( )


Lets see if i understand this correctly. You are trying to show an image by turning an image, that is placed above it, invisible?

It seems that the easier way would be to change the image of the actual imageview your are turning invisible.

image.setImageResource(R.drawable.<image>)

Where you change to the name of the image placed inside your res/drawable-hdpi/mdpi/ldpi folder.


Thread.sleep() is a bad idea because it halts the thread. So if it is the UI-thread, it can not refresh the screen anymore. That's probably what you observe. Use something like

new Handler().postDelayed(new Runnable() { 
  void run() {
      image.setVisibility(View.VISIBLE);
  }
}, 1000);
0

精彩评论

暂无评论...
验证码 换一张
取 消