喜的朋友,我有兩個的FrameLayout在movies.xml即容器,detail_screen。在容器將增加movies.xml其中包含列表視圖,並在detail_screen有一個名爲movie_details.xml。現在想擴張的ListView在detail_screen中以編程方式檢查已經是片段呈現或不。如果提交只是想刪除該片段。我做了follwing和它的工作正常。檢查片段是在framelayout中呈現還是不在android中?
if (getSupportFragmentManager().findFragmentByTag("MyFragment") != null) {
getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentByTag("MyFragment")).commit();
}
但沒有任何其他的方式來尋找是否片段通過編程方式在Android中呈現的或不框架佈局.Thanks提前
不使用findFragmentByTag()/編號 – krishh
你想知道,如果一個片段存在,而無需將它或它的容器的引用?有'getSupportFragmentManager()。getFragments()'它檢索該管理器的片段列表。 – kassim
@kmg我想,以檢查是否已經在我的FrameLayout片段呈現只想刪除片段添加新的片段,否則相同的片段將很好,如果你在使用'getSupportFragmentManager添加不止一次權 – krishh