第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Android:無(wú)法將一個(gè)片段替換為另一個(gè)

Android:無(wú)法將一個(gè)片段替換為另一個(gè)

三國(guó)紛爭(zhēng) 2019-10-30 14:52:16
我需要將Fragment其中一個(gè)替換為Activity另一個(gè)Fragment,以下是的圖層文件Activity:<?xml version="1.0" encoding="utf-8"?><FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"  android:layout_height="fill_parent"  android:id="@+id/home_layout_container">    <fragment android:name="com.foo.FragA"        android:id="@+id/home_list"        android:layout_width="fill_parent"        android:layout_height="fill_parent" />    </FrameLayout>所以默認(rèn)情況下有FragA,現(xiàn)在我想在活動(dòng)中將其替換為FragB,我這樣做了:public void onRegionClicked(Region region) {    RegionInfoFragment rif = RegionInfoFragment.newInstance(region);    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();    ft.replace(R.id.home_list, rif);}但是我有一個(gè)例外:>6:24:40.685: ERROR/AndroidRuntime(9194): Uncaught handler: thread main exiting due to uncaught exception05-06 16:24:40.692: ERROR/AndroidRuntime(9194): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.view.ViewGroup.addViewInner(ViewGroup.java:1857)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.view.ViewGroup.addView(ViewGroup.java:1752)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.view.ViewGroup.addView(ViewGroup.java:1709)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.view.ViewGroup.addView(ViewGroup.java:1689)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:743)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:933)05-06 16:24:40.692: ERROR/AndroidRuntime(9194):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:578)我能做什么?謝謝!
查看完整描述

4 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

您不能替換在布局文件中靜態(tài)定義的片段。您只能替換通過(guò)來(lái)動(dòng)態(tài)添加的片段FragmentTransaction。


查看完整回答
反對(duì) 回復(fù) 2019-10-30
?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試commit()在ft結(jié)束時(shí),需要對(duì)commit()您的更改進(jìn)行通知。


查看完整回答
反對(duì) 回復(fù) 2019-10-30
?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

getFragmentManger()

  .beginTransaction

  .replace(R.id.frame,Yourfragment.newInstance(),null)

  .addtobackstack

  .commit();

人們總是說(shuō)我是一線客,所以這是您的一線客解決方案


查看完整回答
反對(duì) 回復(fù) 2019-10-30
?
明月笑刀無(wú)情

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊

將一個(gè)片段替換為另一個(gè)片段,并在后堆棧中保留先前的狀態(tài):


    // Create new fragment and transaction


    Fragment newFragment = new ExampleFragment();

    FragmentTransaction transaction = getFragmentManager().beginTransaction();


    // Replace whatever is in the fragment_container view with this fragment,

    // and add the transaction to the back stack

    transaction.replace(R.id.fragment_container, newFragment);

    transaction.addToBackStack(null);


    // Commit the transaction

    transaction.commit();


查看完整回答
反對(duì) 回復(fù) 2019-10-30
  • 4 回答
  • 0 關(guān)注
  • 457 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)