Reputation: 10631
Looking at the documentation, there is LinearLayout.addView() but there isn't any LinearLayout.replaceView().
On the other hand, there is LinearLayout.removeView().
Is implementing my own LinearLayout.replaceView() as two simple successive calls to remove+add safe enough? i.e. are there caveats to watch for?
public void replaceView(View oldView, View newView) {
removeView(oldView);
addView(newView);
}
Upvotes: 1
Views: 868
Reputation: 5310
Try this:
public void replaceView(final View oldView, final View newView) {
addView(newView, indexOfChild(oldView));
removeView(oldView);
}
Upvotes: 3