我有ViewPager
PagerSlidingTabStrip
的Activity
爲我ViewPager
每一頁都有fragment
,並在每個fragment
實現的http request
(使用Volley
)加載來自頁面的數據,但是當請求結束時出現錯誤,輸入timeout或者失去連接時,我需要顯示一個對話框,並用選項重做對服務器的調用,防止出現多個對話框的問題,爲每個錯誤打開解決與片段:安卓:避免打開對話框幾次,但允許隱藏和顯示相同的對話框
在此處查看此解決方案:http://www.jorgecoca.com/android-quick-tip-avoid-opening-multiple-dialogs-when-tapping-an-element/
@Override
public void show(FragmentManager manager, String tag) {
if (manager.findFragmentByTag(tag) == null) {
super.show(manager, tag);
}
}
當用戶單擊dialog button
再次嘗試,並關閉對話框並檢查是否有互聯網連接,如果我沒有,對話框應該再次打開,但對話框不會再次顯示,我相信標籤不會被釋放到FragmentManager
。
守則Activity
:
final Button mButton = (Button) this.findViewById(R.id.btn_opendialog);
final DialogFragmentHelper mDialog = new DialogFragmentHelper();
mDialog.setCallbackListener(new OnCallback() {
@Override
public void onCancel() {
}
@Override
public void onConfirm() {
// verify if network available
mDialog.show(MainActivity.this.getSupportFragmentManager(), DialogFragmentHelper.DIALOG_TAG);
}
});
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
mDialog.show(MainActivity.this.getSupportFragmentManager(), DialogFragmentHelper.DIALOG_TAG);
}
});
會有人有解決辦法的建議?
,我對這個問題並不清楚,但是這樣可以解決是的,謝謝! –