我在Tabview
中设置了Activity
。登录成功后,我将转到ActivityTwo
,在其中调用TabView
片段。每个Fragment
从Api加载数据并将其设置在ReyclerView
中。在每个Fragment中,我在Api调用之前显示ProgressDialog
,并在数据加载后关闭它。但是问题是,当TabView Fragment被替换为所有3个Api调用时发生制表符,即使“第一个制表符”上的数据已加载,进度对话框仍在加载,并且我需要通过触摸屏手动将其关闭?
这是First Tab数据调用的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.current_status, container, false);
//----------------------------------------------------------------------
pullRefresh = (SwipeRefreshLayout) v.findViewById(R.id.pullRefresh);
recyclerView = (RecyclerView) v.findViewById(R.id.recyclerView);
recyclerView.setVisibility(View.VISIBLE);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
context = recyclerView.getContext();
controller = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_fall_down);
progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Fetching Records");
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setIndeterminate(true);
getData();
progressDialog.show();
return v;
}
如何解决这个问题?
答案 0 :(得分:0)
如果数据已成功加载,则将其放在您的 LAST if(progressDialog.isShowing()){
progressDialog.dismiss
}
上。
progressDialog.setCanceledOnTouchOutside(false);
奖励提示
总是添加progressDialog.setCancelable(false);
和progressDialog
这会在{{1}}加载时禁用外部触摸,以防止UI中断