Side effects of calling Activity.setContentView() twice in a row

ε祈祈猫儿з 提交于 2019-12-10 15:44:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5808026/side-effects-of-calling-activity-setcontentview-twice-in-a-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!