How to inflate Android View in LinearLayout class?

后端 未结 3 1959
深忆病人
深忆病人 2021-01-04 18:17

I\'ve got a little piece of xml, which I\'ll be using in a lot of places in my app. For this reason I want to store it in a separate file. So I created mywidget.xml in which

3条回答
  •  盖世英雄少女心
    2021-01-04 18:58

    Easiest Solution

    LinearLayout item = (LinearLayout )findViewById(R.id.item);//where you want to add/inflate a view as a child
    
    View child = getLayoutInflater().inflate(R.layout.child, null);//child.xml
    
    item.addView(child);
    
    ImageView Imgitem = (ImageView ) child.findViewById(R.id.item_img);
    
    Imgitem.setOnClick(new ...
    

提交回复
热议问题