2012-05-01 9 views
0

昨日私はアンドロイドの机の時計を作成しました。このために、Hour、分などを表示するRelativeLayoutを作成し、オプションAbout、Exitを表示するメニューを作成しました。うーん、すべてうまくいきますが、About Optionをクリックすると問題が発生します。 LogCatはこの例を示します子供の親のremoveView()を呼び出す

は、だから私はあなたが私を助けることができると思います

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.

... アイブ氏は、このコードについて聞いたが、私はそれを置くと、どのように場所を知らない、私はこれがOKだろうと思ったが、それここで

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

は私が考えるマニフェストファイルの問題、iはないようです、ここでFrmAboutコード

<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> 

をそして:知らない

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

    } 
    } 

[OK]を、それを解決し....問題だったsetcontentview()メソッドを、それを削除し、今では動作します

+1

これを試してください:((ViewGroup)scrollChildLayout.getParent())。removeallViews(); http://stackoverflow.com/questions/6526874/call-removeview-on-the-childs-parent-first –

答えて

0

あなたのコードから私はアクティビティを呼び出す前にすべてのビューを削除する理由を理解できませんでしたか?新しいアクティビティを開始するために、すべてのビューを削除する必要はありません。現在のアクティビティからビューを削除せずにstartActivity(intent)を直接呼び出すことができます。

問題を理解するためにログを投稿してください。

+0

Ok、編集してlogcatエラーを追加しました。 logcatは、FrmAboutを開始する前にremoveView()を呼び出さなければならないと言っているからです... – BamsBamx

0

この質問は以前に尋ねられました。次回は検索を試してみてください! Take a look at the answer here、私は自分のコードでそれを使用し、素晴らしい作品です。

+0

私はあなたが投稿したものを見つけましたが、私はそれを置く必要があるか分かりません....多分最初のコードで???あなたはこれがOKだと思いますか?最後のRelativeLayout fondo =(RelativeLayout)findViewById(R.id.your_layout); '((ViewGroup)fondo.getParent())。removeView(fondo);' – BamsBamx

関連する問題