How to add same view to parent multiple times by inflating it only once

后端 未结 4 1007
小蘑菇
小蘑菇 2020-12-10 10:30

I have a LinearLayout with vertical orientation as parent, I want to add some view programmatically multiple times to this parent. Right now I am inflating the child every t

4条回答
  •  一整个雨季
    2020-12-10 10:47

    You can't, even if you try to create a new view from the old view object the object will be passed by reference not value, and hence you will got an Exception as the childAlreadyHasParent, and so, the only way is to put the view into a for loop with the number of times you want it to be inflated, and this loop must contain the creating process from beginning not only the inflating lines.

提交回复
热议问题