开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜