Check if view element is added to layout or not programmatically

前端 未结 7 820
予麋鹿
予麋鹿 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:18

    Sorry for late reply but you may try this alternative:

    use container.getChildCount(); before adding and after adding a view. Like :

    int x = container.getChildCount();
    
    container.addView(child, params);
    
    int y = container.getChildCount();
    
    if(y > x)
       Toast.makeText(context, "View Successfully Added!", Toas.LENGTH_SHORT).show();
    

提交回复
热议问题