1

I have an imageView inside of a LinearLayout and when I call invalidate on that LinearLayout it doesnt invalidate until the phone sleeps and wake again.

Is there anyway of forcing the LinearLayout to invalidate straight away?

A--C
  • 36,351
  • 10
  • 106
  • 92
Kimmy
  • 3,787
  • 5
  • 22
  • 20
  • What are you trying to accomplish by invalidating the view? – dymmeh Jan 27 '13 at 22:03
  • I am trying to add another imageview inside this linearLayout but it doesnt invalidate until i sleep the phone or press back to go back to the previous activity – Kimmy Jan 27 '13 at 22:18
  • 1
    You don't need to call invalidate if all you're doing is adding another view. Maybe you can post the code where you add the other ImageView – dymmeh Jan 27 '13 at 22:39
  • So basically i am reading in all images from a folder in the SD card and setting all them images to a ImageView and adding it to the linearlayout. – Kimmy Jan 27 '13 at 22:45
  • So my code does atm is first loads in all the images from the folder and sets each of the image to a imageview and adds it to the LinearLayout, then i will click a button which will delete one image from the folder and i want the same image which is deleted from that folder to be deleted in the linear layout so what ive done is called linearLayout.removeAllViews() and then called a method to read all the images from the folder and set each of the image to a Imageview and added them to the linear layout – Kimmy Jan 27 '13 at 22:51

2 Answers2

0

From android documentation about invalidate function

Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

Cristian Holdunu
  • 1,880
  • 1
  • 18
  • 43
-1

This is over 3 years old, so I'm not anticipating a response, but if you don't think your LinearLayout is invalidating because you're not getting any calls to onDraw(), take a look at https://stackoverflow.com/a/17595671/852795:

By default all ViewGroup sub-classes do not call their onDraw method, you should enable it by calling setWillNotDraw(false) link

From the doc:

By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(android.graphics.Canvas) you should clear this flag.

Try adding setWillNotDraw(false); to your LinearLayout.

Community
  • 1
  • 1
Mark Cramer
  • 2,614
  • 5
  • 33
  • 57