3

是否有任何方法將進度對話框添加到sherlock fragment(不是片段活動)的操作欄sherlock中。我必須使用sherlock碎片,因爲在我的應用程序中我使用導航抽屜。 對於片段活動,當我使用以下代碼時,進度對話框正常工作。將進度對話框添加到操作欄sherlock片段中sherlock

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
setContentView(R.layout.search_all_fragment_layout);    
setSupportProgressBarIndeterminateVisibility(true); 

有沒有辦法在碎片中做到這一點?

謝謝。

回答

7

的進度可以通過在活動使用此線顯示:

supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
setSupportProgressBarIndeterminate(true); 
setSupportProgressBarIndeterminateVisibility(true); 

如果你想用它在你的片段,你必須請參考活動:

getActivity().supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
getActivity().setSupportProgressBarIndeterminate(true); 
getActivity().setSupportProgressBarIndeterminateVisibility(true); 

考慮制定方法在您從Activity中調用的Fragment中。

編輯:

有這樣的活動爲您提供方法:

public void activateProgressBar(boolean activite){ 
    setSupportProgressBarIndeterminateVisibility(activate); 
} 

確保你在的onCreate稱這種活動的():

supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); 
setSupportProgressBarIndeterminate(true); 

現在只需要調用這在你的片段:

((YourActivity)getActivity()).activateProgressBar(true/false); 
+0

首先感謝你的回答,你能解釋一下這條線是什麼意思 「考慮在你的Activity中製作一個方法,你從片段調用。」 – Grant

+1

@Grant我編輯我的答案 –

+0

在片段我不能使用這個getActivity()。activateProgressBar(true); 它說:「該方法activateProgressBar(布爾)是未定義類型FragmentActivity」我該怎麼辦這個 – Grant