views:

208

answers:

3

I am having a problem trying to refresh a View in an Android application. I have a button that have a image and what I need to do is to change the image when someone clicked the button.

Where is the problem? The image don't refresh until the activity finished proccessing the code. Any idea how I can refresh the image as soon as It execute the instruction

buttton1.setBackgroundDrawable(getResources().getDrawable(R.drawable.f1));
+1  A: 

Have you considered using the xml side and have the drawables as selectors as then the selectors will get chosen by the particular key/touch event to display the correct graphic..

Fred Grott
A: 

The first thing you do in the onclick listner is change the backgrount of the button

Robin
Yes I know, but the image don't change until all the code is proccessed
A: 

Try running your method that does your processing from a thread.

ficha1.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) { 
        Button bot = (Button) findViewById(R.id.boton1); 
        bot.setBackgroundDrawable(getResources().getDrawable(R.drawable.f2)); 
        //ficha.setText(fichas.get("boton1").toString()); 
        new Thread(
            new Runnable() {
                public void run() {
                    controlJugada(fichas.get("boton1").toString(), bot);
                }
            }
        ).start();
    } 
});
Brian