tags:

views:

55

answers:

1

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 inflate code is pretty simple:

layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.my_layout, this, true);
+1  A: 

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.

CommonsWare
Thanks, I ended up using removeAllViews() before inflating.
Brandon