Questions tagged [android-view-invalidate]

Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

Generally, invalidate() means 'redraw on screen' and results to a call of the view's onDraw() method. So if something changes and it needs to be reflected on screen, you need to call invalidate(). However, for built-in widgets you rarely, if ever, need to call it yourself. When you change the state of a widget, internal code will call invalidate() as necessary and your change will be reflected on screen. For example, if you call TextView.setText(), after doing a lot of internal processing (will the text fit on screen, does it need to be ellipsised, etc.), TextView will call invalidate() before setText() returns. Similarly for other widgets.

If you implement a custom view, you will need to call invalidate() whenever the backing model changes and you need to redraw your view. It can also be used to create simple animations, where you change state, then call invalidate(), change state again, etc.

Official documentation

24 questions
0
votes
1 answer

OnDraw() only called once after loop

I have a program I am writing in android studio that is supposed to play a music note and have a circle expand in size based off an arraylist of coordinates, song-note names and times to play the notes. However, the problem I am having is that all…
rma
  • 1,853
  • 1
  • 22
  • 42
0
votes
1 answer

How to call invalidate() method from another class?

I'm trying to implement pinch zooming functionality on my custom view in my Android application. I have use following class to do it. public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { public…
0
votes
1 answer

ListView / GridView not refreshing inside Fragment

The other elements of the fragment get updated, only listview and gridview that don't. I can see in Logs that the adapter's content is getting changed, but the views only refresh when I click on them or onResume(). I have already tried…
0
votes
1 answer

Can't redraw my canvas bitmap with invalidate();

I need help with my game! I am drawing my playermodel with a bitmap and I want to change the model with an ontouch event, but it is not working and I don't know, what I'm doing wrong: ( First of all here is my playerclass were I'm creating the…
0
votes
2 answers

Timer not working in Android when calling invalidate()

I want to create a flashing effect by drawing a path with color grey, white (matching to the background), and then grey again. I want to flash 3 times, showing gray for 1 sec, white for 1 sec gray again for 1 sec, etc. When I created a Handler for…
Eddev
  • 890
  • 1
  • 10
  • 21
0
votes
0 answers

Android Canvas Lagging

I'm creating a project for a class and I'm experiencing some lag issues. When the map is loaded either nothing will happen so you have to go back and reload it and it'll work for a while or after making some moves my phone/emulator will take a…
0
votes
2 answers

Android invalidateDrawable() not working

I have a bunch of drawables in a custom view. I want the user to be able to press on one or multiple drawables and it changes colors. Currently, each drawable is just a StateListDrawable with two states: state_pressed and not pressed. Every time I…
0
votes
1 answer

Hold animation state between invalidate

I'm trying to conserve view state after invalidate and I'm very unsuccessful. The thing is I have an image, which user can scale (either on right or left side). After he scales it, app will draw points on some locations and after user clicks on…
Klemikaze
  • 369
  • 6
  • 15
0
votes
0 answers

Invalidate a canvas, without redrawing the background

So I have a class which extends the view class, and another class which is receiving data from an external device, when new data comes in a flag is changed, this is where I call invalidate on my view. The problem is it redraws the entire canvas…
1
2