Calling inflate() multiple times in an Android view
I have a View that inherits from LinearLayout that inflates itself. After it has been created and inflated I wanted the ability to inflate a different layout. However, calling inflate() a second time seems to have no effect. Only if I close the activity and open it again is the state reflected in the UI.
Is it possible to call inflate multiple times to dynamically change the layout?
My in开发者_如何学运维flate code is pretty simple:
layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.my_layout, this, true);
Is it possible to call inflate multiple times to dynamically change the layout?
Try removing your child views first. Right now, you are appending the new stuff after the old stuff, AFAICT.
精彩评论