Check if view element is added to layout or not programmatically

前端 未结 7 848
予麋鹿
予麋鹿 2021-01-01 09:47

In my fragment class, I add a child view element programmatically to my layout conditionally :

LinearLayout child = (LinearLayout) inflater.inflate(R.layout.         


        
7条回答
  •  暖寄归人
    2021-01-01 10:25

    Or if you have a view instance to find, you could:

    if (container.indexOfChild(childView) == -1) {
      // Add child to container.
    }
    

提交回复
热议问题