ProgressDialog继续加载,直到Tabview中的所有三个选项卡都在单个选项卡片段上加载内容

时间:2018-08-11 09:37:10

标签: android android-fragments android-recyclerview android-progressbar

我在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;
}  

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

如果数据已成功加载,则将其放在您的 LAST if(progressDialog.isShowing()){ progressDialog.dismiss } 上。

progressDialog.setCanceledOnTouchOutside(false);

奖励提示

总是添加progressDialog.setCancelable(false);progressDialog

这会在{{1}}加载时禁用外部触摸,以防止UI中断