簡體   English   中英

在孩子的父母上調用removeView()

[英]Calling removeView() on the child's parent

昨天我為Android創建了桌面時鍾。 為此,我創建了一個RelativeLayout來顯示Hours,minutes等,並創建了一個菜單來顯示About和Exit ...嗯,一切正常,但是當我單擊About About時出現了問題:它強制關閉並LogCat顯示以下內容:

E/AndroidRuntime(14751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iamaner.T2Speech/com.iamaner.T2Speech.FrmAbout}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

因此,希望您能為我提供幫助...我聽說過此代碼,但是我不知道將其放在何處以及如何放置,我認為這可以,但是似乎不行

final RelativeLayout fondo = (RelativeLayout)findViewById(R.id.your_layout);((RelativeLayout)fondo.getParent()).removeView(fondo); //scrollView.removeView(scrollChildLayout);

這是清單文件,我認為是問題所在,我不知道:

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TimeToSpeechActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape" 
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <activity android:name=".FrmAbout" />
</application>

在這里,FrmAbout代碼:

 public class FrmAbout extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frmabout);

    TextView txtVersion = (TextView)findViewById(R.id.Txtversion);
    TextView txtWarning = (TextView)findViewById(R.id.Txtwarning);
    TextView txtInstructions = (TextView)findViewById(R.id.Txtinstructions);
    TextView txtContact = (TextView)findViewById(R.id.Txtcontact);

    setContentView(txtVersion);
    setContentView(txtWarning);
    setContentView(txtInstructions);
    setContentView(txtContact);

     }
     }

好的,解決了...。問題是setcontentview()方法,將其刪除,現在可以工作了

從您的代碼中,我無法理解為什么在調用About活動之前刪除所有視圖? 這是您的要求嗎,因為不必啟動所有活動就可以刪除所有視圖。.您可以直接調用startActivity(intent)而不從當前活動中刪除視圖。

請發布日志以幫助理解問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM