4

In my app I needed to call findViewbyId() from both onCreate() and from WebChromeClient.onCompletion(). To avoid findViewbyId() returning null I resorted to calling Activity.setContentView(int viewResID) before calling findViewbyId().

It works, but now I am wondering whether I may have created a "time-bomb" in my code down the road.

Are there any caveats that I need to keep in mind when doing something like this?

Community
  • 1
  • 1
uTubeFan
  • 6,664
  • 12
  • 41
  • 65

1 Answers1

8

There is no problem in doing so. You have to reinitialize references (every findViewById needs to be called again) and it might be troublesome if you do it A LOT of times, but it is not a time bomb at all.

ferostar
  • 7,074
  • 7
  • 38
  • 61
  • Thank you! The only reason I am calling Activity.setContentView() more than once is because I need to call findViewById() for a particular view more than once. The tip for having to call again **every** findViewById is invaluable. Thanks so much. – uTubeFan Apr 27 '11 at 17:49