我正在尝试使用dialogFragment更新progressDialog,在AsyncTask
内部管理不同的任务。
除了不确定模式之外,我在进度上所做的每件事都是正确的。
这是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);
}
}
答案 0 :(得分:1)
当bar需要进入不确定模式时,我解决了避免设置进度值的问题:)