1

我正在从文件中读取纬度/经度,创建多边形并将其添加到AsyncTask. 一切正常 - 除了progressDialog在动作开始时总是冻结并在动作完成后关闭。这是我的代码:

更新代码:

   private class shpLoading extends AsyncTask<GoogleMap, List<LatLng>, String> {
              private ProgressDialog dialog;
              private String path; 
                      private int loaded;
              public void setPath(String p){
                     this.path = p;   
              }

              @Override
              protected String doInBackground(GoogleMap... params) {    

                    final ShpReader shpRead = new ShpReader();



                        try {
                            shpRead.read(path);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (InvalidShapeFileException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                          dialog.setMax(shpRead.daugiakampiai().size());
                          int i = 0;
                          for(List<LatLng> a: shpRead.polygons()){                                                            
                              function.arAntLinijos(a);
                              for(int h = 0; h < a.size()-1; h++){
                                  LatLng point = function.midPoint(a.get(h), a.get(h+1));
                                  a.add(h+1, point);
                                  h++; 

                                  if(i > 3000){
                                      message("You reached max count!");
                                      break;
                                  }
                              }
                              publishProgress(a);

                              i++;                           
                          }

                    return "Done";
              } 
                  @Override
              protected void onPreExecute() {                                                                         
                      dialog = new ProgressDialog(Measuring.this);   
                      dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
                      dialog.setMessage(getString(R.string.loading));
                      dialog.setCancelable(false);
                      dialog.setProgress(0);                         
                      dialog.show();
              }                                       
              }

              @Override
              protected void onProgressUpdate(List<LatLng>... values) {
                            dialog.setProgress(loaded++);
                Polygon daug = mMap.addPolygon(new PolygonOptions()
                  .addAll(values[0])
                  .strokeWidth(1)
                  .strokeColor(Color.RED)
                  .fillColor(0x3F00FF00));

                  plotai.add(new Polygons(db.getMaxFieldID()+1, daug)); 
                  daug = null;                               
                }

              @Override
              protected void onPostExecute(String result) {
                    dialog.dismiss();

              }                      
       } 
4

1 回答 1

2

因为您不应该在onProgressUpdate方法中绘制多边形,而是在doInBackground方法中。在onProgressUpdate方法中,您必须更新ProgressDialog对象的进度(在您的代码ProgressDialog中显示,但根本没有更新其进度)。

于 2013-10-24T08:12:16.833 回答