0

我正在尝试在一个AsyncTask使用 dialogFragment 更新progressDialog 中管理不同的任务。除了不确定模式外,我在进度上所做的每一件事都是正确的。

这是 AsyncTask 内部流程的示例:

Map<String,String> map = new HashMap<String,String>();
map.put("progress", "0");
map.put("indeterminate", "n");
map.put("text","Download tab1");
map.put("max",""+tab_size);
publishProgress(map);

map.clear();
for(int i=0;i<tab_size;i++){       
   map.put("progress", ""+i);
}

map.clear();
map.put("progress", "0");
map.put("indeterminate", "y"); // DOES NOT WORK!
map.put("text","Extract tab1");
map.put("max","0");
publishProgress(map);


    @Override
protected void onProgressUpdate(Map<String,String>... values) {
    Map<String,String> map = values[0];
    if(map.containsKey("progress"))
        fragment.setActual(Integer.parseInt(map.get("progress")));
    if(map.containsKey("max"))
        fragment.setMax(Integer.parseInt(map.get("max")));
    if(map.containsKey("text"))
        fragment.setText(map.get("text"));
    if(map.containsKey("indeterminate")){
        boolean ind = map.get("indeterminate").equals("y");
        fragment.setIndeterminate(ind);
 }

片段在哪里:

public class PropDialogFragment extends DialogFragment {

    public static Dialog dialog;

    private static PropDialogFragment newInstance() {
        PropDialogFragment f = new PropDialogFragment();
        return f;
    }
    public static PropDialogFragment showUpdatesDialog(Activity activity){
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        Fragment prev = activity.getFragmentManager().findFragmentByTag("updateDialog");
        if (prev != null) 
            ft.remove(prev);

        ft.addToBackStack(null);

        DialogFragment newFragment = newInstance();
        newFragment.show(ft, "updateDialog");
        return (PropDialogFragment)newFragment;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setTitle("Update");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setMessage("");
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        return dialog;
    }

    public void setText(String text){
        ((ProgressDialog)getDialog()).setMessage(text);
    }
    public void setIndeterminate(boolean indeterminate){
        ((ProgressDialog)getDialog()).setIndeterminate(indeterminate);
    }
    public void setMax(int max){
        ((ProgressDialog)getDialog()).setMax(max);
    }
    public void setProgress(int progress){
        ((ProgressDialog)getDialog()).setProgress(progress);
    }


}
4

1 回答 1

1

我解决了当栏需要进入不确定模式时避免设置进度值的问题:)

于 2013-07-02T08:01:56.260 回答