简体   繁体   中英

I need refresh imageView with a button(invalidate doesn't work)

I have a custom ImageView where i can draw, zoom and paint points(coordinates).

I have a button "reset" which delete the coordinates i draw

BUT my imageView doesn't refresh when i click, it refresh after, when I touch the screen.

Gonna see some code

Here the onClick of the buttons- btnRes

is the button i need help!

//this method is on the "Main extends Activity"
public void onClick(View v) {
        switch(v.getId()){
        case R.id.btnFin:
            break;
        case R.id.btnInv:
            break;
        case R.id.btnRes://start over
            Imagen.listaPtos.clear();
            //refreshing image
            imagen.invalidate();//dont works
            imagen.refreshDrawableState();//dont works neither
            break;
        }
    }

Some thing about My class Imagen for understand an after the code

public class Imagen extends ImageView

static ArrayList <Marking> listaPtos = new ArrayList<Marking>(); 

some code from Imagen

@Override
public void onDraw(Canvas c){
    Log.d("onDraw","pinta="+pinta);
    c.drawBitmap(bitmap, matrix, paintFondo);

    if(listaPtos!=null){
        for(Marking mark:listaPtos){                
            c.drawBitmap(cruz, mark.x, mark.y, paintPuntos);
        }
    }
}

//for coordinates
class Marking{
int x;
int y;
Marking(int x, int y){
    this.x = x;
    this.y = y;
}
Marking(){}
int getX(){
    return x;
}
int getY(){
    return y;
}
void setX(int x){
    this.x = x;
}
void setY(int y){
    this.y = y;
}   

}

any ideas?

i solve it with this code insithe onDraw:

((Main) context).runOnUiThread(new Runnable() {
           @Override
           public void run() {

               Imagen.this.invalidate();

           }
     });

not the best solution but the one who works

thx: https://stackoverflow.com/a/21732444/4116091

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM