当调用我的类时,我想实现一个progessDialog。我知道如何为使用progressDialog的片段类实现AsyncTask。但是这里有一个不使用asyncTask的片段类。
这个片段所做的是显示一些新闻细节时,它被称为。我想在新闻加载时显示一个progressDialog,并在新闻加载并准备好到display.How时停止progressDialog,我可以这样做吗?我是新手,请帮帮我
我的碎片类
package com.fortuna.cinemalk;
public class NewsDetailFragment extends Fragment {
private ViewPager view1;
private ViewPageAdapter adapter;
private Activity activity;
private CommonVariable commonVariable;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.newsdetail_fragment, container,
false);
activity = this.getActivity();
commonVariable = (CommonVariable) activity.getApplication();
view1 = (ViewPager) view.findViewById(R.id.listviewpager);
adapter = new ViewPageAdapter(commonVariable.getNewsDescription(),
Element.NEWS_DETAIL.getType(), activity);
view1.setAdapter(adapter);
return view;
}
}发布于 2014-09-02 09:54:36
你需要这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true" />
</RelativeLayout>加载数据后,只需隐藏这个进度栏,如下
progressBarObj.setVisibility(false);发布于 2014-09-02 09:42:18
对我来说最好的选择是创建一个自定义处理程序来修改proggress组件:
public final class ProgressBarComponentViewHandler extends Handler {
private ProgressBar progressLayout;
private Activity mActivity;
public LoadingComponentViewHandler(Activity activity, ProgressBar progressLayout) {
this.progressLayout = progressLayout;
this.mActivity=activity
}
public void update(int status){
Message m = new Message();
Bundle bundle = new Bundle();
bundle.putInt("status", status);
m.setData(bundle);
super.sendMessage(m);
}
public void handleMessage(Message msg) {
Bundle b = msg.getData();
Integer status = b.getInt("status", 0);
progressLayout.setProgress(status);
}
}在你的片段里:
loadingComponentView = (ProgressBar) yourRootView.findViewById( R.id.progress_bar_component_view );
progressBarDialogHandler = new ProgressBarViewHandler(getActivity(), loadingComponentView);最后,更新您的观点:
progressBarDialogHandler.update(80);//To set 80% of progressbar.发布于 2014-09-02 09:53:21
您可以从您的ProgressDialog或服务中显示ProgressDialog,也可以像静态和调用AsyncTask或服务那样以片段形式初始化progressDialog,但是您需要检查progressDialog!=null
(因为当新闻被加载时,我需要取消进度)
https://stackoverflow.com/questions/25619947
复制相似问题