开发者

How to add views in an android application programmatically

I've been trying to add a view in my android app, but it keeps throwing an exception. The view I'm adding is a linearlayout that contains an imageview and a nested linearlayout with 3 textviews. The view I'm adding it to is a LinearLayout with a checkbox, 2 textviews, and a nested relativelayout with a button and an editText.

They are in separate xml files, and I've inflated the view I'm adding. However, when I call addView(), it throws the following exception:

06-10 09:24:33.094: ERROR/AndroidRuntime(开发者_JAVA百科5743): java.lang.RuntimeException: Unable to resume activity {com.projects.twitterOAuth/com.projects.twitterOAuth.twitterOAuth}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.


When you inflate your child view, make sure that parent parameter (last one) is set to null.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜