<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Blogger Scott

    The specified child already has a parent. You must call removeView() on the child's parent first.的解決辦法

        出現The specified child already has a parent. You must call removeView() on the child's parent first.這個問題,一般原因是對layout.xml的使用理解不清楚。
        以xml文件方式來設計界面的布局,如果需要動態的對xml文件中的各類View進行修改的話,在代碼中使用時,不能直接使用this.findViewById(R.id.***)來獲取xml文件中的每個View,然后再將這些View加入到代碼中的Layout中來進行顯示。正確的做法應該是使用inflater。

        舉例如下:
    xml布局文件test.xml為:
     1<?xml version="1.0" encoding="utf-8"?>
     2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3    android:orientation="vertical" android:layout_width="fill_parent"
     4    android:layout_height="fill_parent">
     5
     6    <TextView android:id="@+id/tv1" android:layout_gravity="center_vertical"
     7        android:layout_width="wrap_content" android:layout_height="wrap_content"
     8 />
     9
    10    <TextView android:id="@+id/tv2" android:layout_gravity="center_vertical"
    11        android:layout_width="wrap_content" android:layout_height="wrap_content"
    12         />
    13
    14    <TextView android:id="@+id/tv3"
    15        android:layout_gravity="center_vertical" android:layout_width="wrap_content"
    16        android:layout_height="wrap_content"  />
    17
    18    <ImageView android:src="@drawable/line" android:layout_width="fill_parent"
    19        android:layout_height="fill_parent"  />
    20
    21</LinearLayout>


    如果你需要使用這個布局XML文件,并根據自己的需要,將其中三個TextView的文字做更改,則在代碼中應該這樣去使用:
     1     
     2     LayoutInflater inflate = (LayoutInflater)
     3         getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     4         LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.poemshowlist, null); 
     5         
     6         ((TextView)layout.findViewById(R.id.tv1)).setText(text1);
     7         ((TextView)layout.findViewById(R.id.tv2)).setText(text2);
     8         ((TextView)layout.findViewById(R.id.tv3)).setText(text3);
     9         
    10         LinearLayout ll= new LinearLayout(this);
    11         ll.addView(layout);
    12         setContentView(ll);
    13         
    14         
    15





    posted on 2010-12-11 22:28 江天部落格 閱讀(8093) 評論(0)  編輯  收藏 所屬分類: Android

    主站蜘蛛池模板: 中文字幕免费不卡二区| 四虎国产精品成人免费久久| 久久免费精品视频| a级亚洲片精品久久久久久久| 黄网站色视频免费看无下截| 免费国产高清视频| 免费很黄无遮挡的视频毛片| 亚洲av再在线观看| 青青青视频免费观看| 亚洲日本一区二区三区在线不卡| 九九久久精品国产免费看小说 | 亚洲精品福利在线观看| 一级做a爰全过程免费视频| 中文字幕亚洲综合久久| 日本三级2019在线观看免费| 中文字幕亚洲男人的天堂网络 | 抽搐一进一出gif免费视频| 国产亚洲日韩在线三区| 精品一卡2卡三卡4卡免费视频| 亚洲人成电影福利在线播放| 国产a视频精品免费观看| 最新国产精品亚洲| 亚洲国产91精品无码专区| 国产福利免费视频 | 亚洲AV日韩AV永久无码色欲| 国产午夜鲁丝片AV无码免费| 一区二区三区在线免费| 亚洲va久久久噜噜噜久久男同| 日韩人妻无码精品久久免费一| 亚洲制服丝袜一区二区三区| 在线免费观看一级片| 新最免费影视大全在线播放| 久久亚洲精品成人| 成人a免费α片在线视频网站 | 亚洲精品永久www忘忧草| 99精品全国免费观看视频| 黄色一级免费网站| 亚洲理论片中文字幕电影| 国产黄色片在线免费观看| 国产一级a毛一级a看免费人娇| 91午夜精品亚洲一区二区三区|