How to implement LinearLayout.replaceView() -- or ViewGroup.replaceView() in general
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开发者_JAVA百科 watch for?
public void replaceView(View oldView, View newView) {
removeView(oldView);
addView(newView);
}
Try this:
public void replaceView(final View oldView, final View newView) {
addView(newView, indexOfChild(oldView));
removeView(oldView);
}
精彩评论