且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查是否存在来自布局充气机的视图,然后再添加一个视图

更新时间:2023-01-07 08:41:33

选项1:使用boolean accountsAdded=false;,在需要时将其设置为true

Option #1: Use boolean accountsAdded=false;, setting it to true when needed

选项2:使用l.findViewById(R.id.accounts)并查看是否返回null

Option #2: Use l.findViewById(R.id.accounts) and see if that returns null

顺便说一句,如果R.layout.forms的根窗口小部件不是R.id.accounts View,您将崩溃,因此请通过addView()view而不是item添加到l.

BTW, you will crash if the root widget of R.layout.forms is not the R.id.accounts View, so please add view, not item, to l via addView().