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
14
votes
4 answers

Why is requestLayout being called directly after invalidate

I'm learning about custom views and wanted to learn about invalidate() and requestLayout(). Please refer to this answer and its diagram: https://stackoverflow.com/a/25846243/4243687 invalidate() tells Android that the state of the view has changed…
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
5
votes
1 answer

Difference between ListView invalidate() vs invalidateViews()?

What is the difference between ListView.invalidate() and ListView.invalidateViews()? For me, invalidate() alone did not work. Whereas invalidateViews() worked just the way I wanted i.e. to redraw the List items.
Sid
  • 1,270
  • 2
  • 15
  • 30
2
votes
1 answer

Updating only a portion of View without using invalidate(Rect)

In my current application I am using invalidate(Rect) to update a portion of my current view but as of API 28 this method is deprecated. So my questions are: 1.Are there any other way to update only a portion of view? 2.What are the consequences of…
titor
  • 35
  • 1
  • 8
2
votes
1 answer

Invalidate is failing to call onDraw when returning to an activity that has a custom view

I have inherited some code hence I don't have true freedom to change it. :( I have a main activity, from which other activities (I will refer to these as sub activities from now on) are called. Whenever one of these completes, it calls finish and…
greysqrl
  • 937
  • 3
  • 13
  • 31
1
vote
0 answers

How to allow users to draw only within a specified area in Android?

In my Android Project I have a drawView which user can draw. And it draw a body shape by using x Coordinates, y Coordinates and Bitmap.setPixel. A example of the body shape: https://ibb.co/KDNXhhX. What I want to do is, that user can draw anywhere,…
diveincode
  • 45
  • 4
1
vote
0 answers

Add sticker only once using invalidate()

On clicking 2nd sticker it should display the second sticker alone (the first one should be removed). current output when clicking in sticker 1(yellow),it display sticker 1 on screen and when sticker 2 (red) is clicked the previous sticker is still…
1
vote
0 answers

Invalidate() not calling onDraw

Yesterday I asked a question pertaining to Android graphics, and now that I have the basis up and running, I've made a rendering loop inside of my custom view class. protected void render() { long startTime = System.nanoTime(); long…
jamlab
  • 78
  • 6
1
vote
1 answer

Custom View class' onDraw isn't called by Invalidate

Screen is white & the System.out.println() within onDraw in never called. This is my activity_main.xml The custom…
eikai
  • 93
  • 1
  • 3
1
vote
1 answer

Why does partial invalidate span the entire View?

I am trying to partially invalidate an android View. I use View.invalidate( l, t, b, r ) and it appears to invalidate vertically (top and bottom) values correctly, however, no matter which left and right values I use, it invalidates entire across…
Anthony Massie
  • 139
  • 1
  • 9
1
vote
1 answer

Update ListView footer

I've a ListView with a footer View that contains a TextView that can be changed dynamically according to the language selected. When I select a different language I update my ListView items: mBaseAdapter.updateItems(items); BaseAdapter: public void…
GuilhE
  • 11,591
  • 16
  • 75
  • 116
0
votes
2 answers

How to call onDraw(Canvas canvas) function of CustomView in Android?

I generate an ellipse and I try to reshape with respect to sweepAngle_speed that u can see below. This sweepAngle_speed come from MainActivity.java. In MainActivity.java, I create a seekbar and I use an algorithm between value of seekbar and…
0
votes
2 answers

How to get View.invalidate working within Click Listener

I want to redraw a customview multiple times within a for loop in a ClickListener. However, the view is only refreshed once on completion of the ClickListener code, not within the for loop. Here is the relevant code snippet vw =…
Doug Conran
  • 437
  • 1
  • 5
  • 17
0
votes
0 answers

HOW do you invalidate a fragment view?

Alright, so I have a fragment that displays user account information. The way this works is it issues a request that may or may not touch the server, depending on what information is already cached. When the information is available, there's a…
User1291
  • 7,664
  • 8
  • 51
  • 108
0
votes
1 answer

invalidate() doesn't refresh View

i'm struggling with this for a while, not sure if because almost 2 years of absence in Android DEV or my stupidity, I've tried everything and just cannot redraw my screen even if invalidate() is happening. Here's some…
0
votes
0 answers

Can't change vector drawable for a custom view during runtime

I have implemented a custom view which looks like a seekbar with drawable attached at end Custom Score bar. I have provided methods to change colour for progress, change width of the progress(along with the rocket icon), and change the icon…
1
2