在我第一次更改應用程序中片段的可見性時,片段顯示的不是我設置顯示的片段。Android - 隱藏/顯示片段顯示錯誤的片段
我的佈局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<fragment
android:id="@+id/act_main_frag_top_bar"
class="br.com.myapp.fragments.TopBarFragment"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<fragment
android:id="@+id/act_main_frag_toolbar"
class="br.com.myapp.fragments.ToolbarFragment"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<!-- Tabs -->
<fragment
android:id="@+id/act_main_frag_twitter"
class="br.com.myapp.fragments.TwitterFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<fragment
android:id="@+id/act_main_frag_facebook"
class="br.com.myapp.fragments.FacebookFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<fragment
android:id="@+id/act_main_frag_tv_show"
class="br.com.myapp.fragments.TVShowFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<fragment
android:id="@+id/act_main_frag_info"
class="br.com.bluepen.mixtv.fragments.InfoFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<fragment
android:id="@+id/act_main_frag_streaming"
class="br.com.myapp.fragments.StreamingFragment"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
</LinearLayout>
而且myActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager manager = getSupportFragmentManager();
mStreamingFrag = (StreamingFragment) manager.findFragmentById(R.id.act_main_frag_streaming);
mFacebookFrag = (FacebookFragment) manager.findFragmentById(R.id.act_main_frag_facebook);
mTwitterFrag = (TwitterFragment) manager.findFragmentById(R.id.act_main_frag_twitter);
mTVShowFrag = (TVShowFragment) manager.findFragmentById(R.id.act_main_frag_tv_show);
mInfoFrag = (InfoFragment) manager.findFragmentById(R.id.act_main_frag_info);
mToolbar = (ToolbarFragment) manager.findFragmentById(R.id.act_main_frag_toolbar);
mToolbar.setListener(this);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.show(mStreamingFrag);
transaction.commit();
}
中的onCreate後,片段越來越表現爲TwitterFragment,而不是StreamingFragment我設置在最後的展現onCreate方法。
我找到了問題。檢查我的答案吼叫。 – jonathanrz
對不起,我之前沒有看到......這幾乎就是我在說的! :-) – user2606414