Skip to content Skip to sidebar Skip to footer

Android: Clean My View When I Click Button

I create a view and use canvas drawing something. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyViewCircle myViewCircle =

Solution 1:

onDraw() is called if you click the button and your button changes, so you can check in the onDraw() method if the button was clicked.

Solution 2:

Try

@OverrideprotectedvoidonDraw(Canvas canvas) {
        if(shouldDraw){
           super.onDraw(canvas);
           Paintpaint=newPaint();
           paint.setAntiAlias(true);
           paint.setColor(Color.RED);
           canvas.drawCircle(50, 50, 100, paint);
        }else
           Canvas.drawColor(Color.BLACK);

    }

and in the onClick

shouldDraw = false;
view.invalidate();

Solution 3:

what is img01, if its another layout/view, you can call Ex: img01.removeAllViews().

Post a Comment for "Android: Clean My View When I Click Button"