2016-04-15 107 views
1

我的片段擴展了其中包含CMYJsonHttpResponseHandler的BaseFragment。如果處理程序返回錯誤號碼-622。基礎片段將啓動一個對話框。 和我的兩個片段在同一個Activity中。所以對話框會創建兩次。但我想在活動中創造一次。活動代碼是這樣的:同一活動中的兩個片段

CMYGoodsListFragment commodityFragment = new CMYGoodsListFragment(this); 
     Bundle commodityBundle = new Bundle(); 
     commodityBundle.putString(KEY_INTENT_ID, "1"); 
     commodityFragment.setArguments(commodityBundle); 
     fragments.add(commodityFragment); 

     CMYGoodsListFragment serviceFragment = new CMYGoodsListFragment(this); 
     Bundle serviceBundle = new Bundle(); 
     serviceBundle.putString(KEY_INTENT_ID, "2"); 
     serviceFragment.setArguments(serviceBundle); 
     fragments.add(serviceFragment); 
+0

請分享你的代碼從哪裏調用對話框? –

+0

如何判斷對話框已經存在 –

+0

我們有方法alert.isShowing(); –

回答

0

使用共享偏好來記住是否顯示對話框。

+0

其他活動也會對話。如果記得對話。它只會在應用程序中創建一次。我想對嗎? –

+0

您可以附上顯示對話框的標籤,並且可以在每次對話框顯示 –

0

請嘗試使用以下代碼。

private Dialog dialog = null; 

    private void showDialog() 
    { 
      if(dialog!=null && dialog.isShowing()) 
       return; 
      /** Here create dialog */ 
    } 
+0

thx時以這種方式解除對話框的情況下重置首選項。我會嘗試 –

+0

我試過了,但它不起作用。 –

相關問題