我有一個片段,增加了一些基於類別的動態用戶界面。我需要顯示一個進度對話框,並在用戶界面生成時關閉它。我在類別獲取過程的開始和結束以及ui生成結束時調用pd.show()和pd.hide()。仍然我的進度對話框沒有被解僱。進度對話框沒有被解僱的片段
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setTrackedPageName(R.string.analytics_select_service);
pd = new ProgressDialog(getContext());
pd.setIndeterminate(true);
pd.setMessage("Preparing information..");
pd.setCancelable(false);
pd.show();
}
@Override
public void onAttach(Context context)
{
super.onAttach(context);
App.from(context).inject(this);
categoriesSubscription = null;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_service_selection, container, false);
if (view != null)
{
ButterKnife.inject(this, view);
// We're recreating the view - we must be at the top of the scrollview!
isScrolledDown = false;
}
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (Categories.hasChildren(category))
{
populateWithCategories(category.getChildren());
}
else
{
categoriesSubscription = categories.list()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.onErrorResumeNext(Observable.empty())
.subscribe(this::populateWithCategories);
}
}
@Override
public void onDetach()
{
super.onDetach();
if (categoriesSubscription != null && !categoriesSubscription.isUnsubscribed())
{
categoriesSubscription.unsubscribe();
}
}
@Override
public String getTitle()
{
return null;
}
@Override
public float getDesiredActionBarElevation()
{
return isScrolledDown ? ActionBarModifyingContent.DEFAULT_ELEVATION : 0;
}
private void populateWithCategories(List<Category> categories)
{
for (int i = 0; i < categories.size(); i++)
{
Category category = categories.get(i);
if (Categories.isKnown(category)
&& Categories.isValid(category))
//&& Categories.hasAllowedGenders(category))
{
addService(category, i);
}
}
getActivity().runOnUiThread(new Runnable() {
public void run() {
pd.dismiss();
pd.hide();
pd.cancel();
}
});
}
我應該在哪裏打電話pd.dismiss或pd.hide或pd.cancel?
正在顯示的數據? –
是的它正在顯示 – Ackman