android - ProgressDialog not showing up within a Fragment -


i have following class:

...  public class fragmentmapa extends fragment {      /*      * atributos      */     private static string log_tag = "fragmentmapa";      private homeactivity homeactivity;     private googlemap mmapa;      private drawerlayout mdrawer;     private actionbardrawertoggle mdrawertoggle;     private listview mdrawerlist;     private listview mdrawerrightlist;     private relativelayout mdrawerrelativelayout;     private string[] mrightdrawermenutitles;     private imageview mdiputacionlogo;      private incidenciasfetchasynctask mfetchincidenciastask;     private incidencias mis;     private camarasfetchasynctask mfetchcamarastask;     private camaras mcams;     private viabilidadesinvernalesfetchasynctask mfetchviabilidadesinvernalestask;     private viabilidadesinvernales mvis;      private static latlng pos_central = new latlng(43.243968,-2.896957);     private static latlng limitesuroestebizkaia = new latlng(42.895853,-3.594589);     private static latlng limitenorestebizkaia = new latlng(43.540351,-2.180099);     private static final latlngbounds bounds = new latlngbounds(limitesuroestebizkaia, limitenorestebizkaia);      private arraylist<marker> markersincidencias = new arraylist<marker>();     private arraylist<marker> markersobras = new arraylist<marker>();     private arraylist<marker> markerscamaras = new arraylist<marker>();     private arraylist<marker> markersviabilidadinvernal = new arraylist<marker>();      /*      * métodos      */      public fragmentmapa() {      }      @override     public void onattach (activity activity) {         super.onattach(activity);         homeactivity = (homeactivity) activity;          mrightdrawermenutitles = getresources().getstringarray(r.array.mapa_submenu_options);          mdrawer = homeactivity.getmdrawer();         mdrawerrightlist = homeactivity.getmdrawerrightlist();         mdrawerrightlist.setadapter(new arrayadapter<string>(                 homeactivity.getsupportactionbar().getthemedcontext(),                  r.layout.rightdrawer_map_list_item,                 mrightdrawermenutitles                 ));          mdrawerrightlist.setonitemclicklistener(new draweritemclicklistener());     }      @override     public void oncreate (bundle savedinstancestate) {         super.oncreate(savedinstancestate);       }      @override     public view oncreateview (layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          view rootview = inflater.inflate(r.layout.mapa, container, false);          setupmapifneeded();          return rootview;      }      private void setupmapifneeded() {          if( mmapa == null ){             supportmapfragment smf = (supportmapfragment) getchildfragmentmanager().findfragmentbyid(r.id.mapaprincipal);              if( smf != null ){                 //toast.maketext(getactivity(), "vaaamooss", toast.length_short).show();                 mmapa = smf.getmap();             }/*else{                 toast.maketext(getactivity(), "smf es null...", toast.length_short).show();             }*/              if( mmapa != null ){                  setupmap();              }          }      }      private void setupmap() {          //toast.maketext(getactivity(), "a configurar el mapa!!", toast.length_short).show();          cameraposition campos;         campos = new cameraposition.builder()         .target(pos_central)          .zoom((float) 9.5)         .build();          final cameraupdate camupd =                 cameraupdatefactory.newcameraposition(campos);          mmapa.animatecamera(camupd);         mmapa.setoncamerachangelistener(new oncamerachangelistener() {              @override             public void oncamerachange(cameraposition newpos) {                  float maxzoom = 17.0f;                  if( !bounds.contains(newpos.target) ){                     //mover la cámara al centro si se                      //va más allá de los límites                      mmapa.animatecamera(camupd);                 }                  if(newpos.zoom > maxzoom){                     mmapa.animatecamera(cameraupdatefactory.zoomto(maxzoom));                 }              }         });          mmapa.setoninfowindowclicklistener( new oninfowindowclicklistener(){              public void oninfowindowclick(marker amarker) {                  toast.maketext(getactivity(), "info window pulsado", toast.length_short).show();                 if( markerscamaras.contains(amarker) ){                      camara c = mcams.getcamarabycoord(amarker.getposition());                      homeactivity.showcamerafragment(c);                  }             }          });      }      @override     public void onactivitycreated (bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);      }      @override     public void onviewstaterestored (bundle savedinstancestate) {         super.onviewstaterestored(savedinstancestate);      }      @override     public void onstart () {         super.onstart();      }      @override     public void onresume () {         super.onresume();      }      @override     public void onpause () {         super.onpause();     }      @override     public void onstop () {         super.onstop();     }      @override     public void ondestroyview () {         super.ondestroyview();     }      @override     public void ondestroy () {         super.ondestroy();     }      @override     public void ondetach () {         super.ondetach();     }      /* click listener listview in navigation drawer */     private class draweritemclicklistener implements onitemclicklistener {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             final int thepos = position;             mdrawer.setdrawerlistener( new drawerlayout.simpledrawerlistener(){                  @override                 public void ondrawerclosed(view drawerview) {                      boolean waschecked = !mdrawerrightlist.isitemchecked(thepos);                      //toast.maketext(homeactivity, "item pulsado: " + waschecked, toast.length_short).show();                     mdrawerrightlist.setitemchecked(thepos, !waschecked);                      switch (thepos) {                         case 0:                             //incidencias                             //toast.maketext(homeactivity, "incidencias", toast.length_short).show();                              if(!waschecked){                                 //toast.maketext(homeactivity, "incidencias estaba sin pulsar", toast.length_short).show();                                  getincidenciasobras();                                 introducirincidencias();                             }else{                                 //toast.maketext(homeactivity, "incidencias estaba pulsado", toast.length_short).show();                                 removeincidenciasmarkers();                             }                              break;                          case 1:                             //obras                             //toast.maketext(homeactivity, "obras", toast.length_short).show();                              if(!waschecked){                                 //toast.maketext(homeactivity, "obras estaba sin pulsar", toast.length_short).show();                                 getincidenciasobras();                                 introducirobras();                             }else{                                 //toast.maketext(homeactivity, "obras estaba pulsado", toast.length_short).show();                                 removeobrasmarkers();                             }                              break;                            case 2:                             //cámaras                             //toast.maketext(homeactivity, "cámaras", toast.length_short).show();                              if(!waschecked) {                                 getcamaras();                                 introducircamaras();                             }else                                 removecamarasmarkers();                             break;                          case 3:                             //viabilidad invernal                             //toast.maketext(homeactivity, "viabilidad invernal", toast.length_short).show();                              if(!waschecked){                                 getviabilidadesinvernales();                                 introducirviabilidadinvernal();                             }else                                 removeviabilidadinvernalmarkers();                             break;                          default:                             //toast.maketext(homeactivity, "default", toast.length_short).show();                             break;                      }                  }              });              if(mdrawer.isdraweropen(gravity.end))                 mdrawer.closedrawer(mdrawerrightlist);         }     }      private void getviabilidadesinvernales(){         mvis = viabilidadesinvernales.getinstance();         if(mvis.isemptyviabilidadesinvernales()){             mfetchviabilidadesinvernalestask = new viabilidadesinvernalesfetchasynctask(homeactivity);             try {                 mvis = mfetchviabilidadesinvernalestask.execute("es").get();             } catch (interruptedexception e) {                 log.e(log_tag, "error interruptedexception: " + e.getmessage());                 e.printstacktrace();             } catch (executionexception e) {                 log.e(log_tag, "error executionexception: " + e.getmessage());                 e.printstacktrace();             }         }      }      ...      private void introducirviabilidadinvernal() {          if(markersviabilidadinvernal.isempty()){             marker amarker;              (viabilidadinvernal vi : mvis.getviabilidades()) {                  string estado = "";                 bitmapdescriptor icon;                 if(vi.getestado() == puertoestado.abierto){                     estado = getresources().getstring(r.string.mapa_puerto_abierto);                     icon = bitmapdescriptorfactory.fromresource(r.drawable.marker_puertoabierto);                 }else{                     //vi.getestado() == puertoestado.cerrado                     estado = getresources().getstring(r.string.mapa_puerto_cerrado);                     icon = bitmapdescriptorfactory.fromresource(r.drawable.marker_puertocerrado);                 }                  amarker = mmapa.addmarker(new markeroptions()                 .position(vi.getcoord())                 .title(vi.gett())                 .snippet(estado)                 .icon(icon));                  markersviabilidadinvernal.add(amarker);              }          }      }       private void removeviabilidadinvernalmarkers() {          for(marker amarker : markersviabilidadinvernal){             amarker.remove();         }      }      ...      private class viabilidadesinvernalesfetchasynctask extends asynctask<string, void, viabilidadesinvernales>{          private progressdialog mpd;         private homeactivity owneractivity;         private context context;         private exception exceptiontobethrown;          public viabilidadesinvernalesfetchasynctask(activity activity){             this.owneractivity = (homeactivity) activity;             context = activity;             this.exceptiontobethrown = null;             mpd = new progressdialog(context);         }          @override         protected void onpreexecute() {             super.onpreexecute();             mpd.settitle("cargando");             mpd.setmessage("miralo");             //mpd.settitle(getresources().getstring(r.string.mapa_cargando_titulo));             //mpd.setmessage(getresources().getstring(r.string.mapa_cargando, getresources().getstring(r.string.mapa_cargando_elemento_viabilidad)));             mpd.setcancelable(false);             mpd.setindeterminate(true);             mpd.setprogressstyle(progressdialog.style_spinner);             mpd.show();          }          @override         protected viabilidadesinvernales doinbackground(string... params) {             string idioma = params[0];             if(!idioma.equalsignorecase("es") && !idioma.equalsignorecase("eu")){                 idioma = "es";             }             systemclock.sleep(5000);             viabilidadesinvernalesparser vip = new viabilidadesinvernalesparser();             viabilidadesinvernales lasviabilidades = vip.parse(idioma);              log.d(log_tag, lasviabilidades.tostring());              viabilidadesinvernales vis = viabilidadesinvernales.getinstance();              return vis;          }          @override         protected void onpostexecute(viabilidadesinvernales vis) {             super.onpostexecute(vis);             mvis = vis;              if(mpd != null){                 mpd.dismiss();             }              // check if exception exists.             //if (exceptiontobethrown != null) {                 //todo                 //owneractivity.handlexxx();                 //throw exceptiontobethrown;             //}         }      }     ....  } 

the aim show dialog (progressdialog) when asynctask executed, dialog remains in front of ui moment , then, map (which being shown previously) returns front. more exactly, launch application (home activity), open left drawer, press mapa , go current fragment. empty map shown. open right drawer , press button. afterwards, process of launching asynctask executed (and desired progressdialog).

i don't know why, progressdialog not being shown, have realised "sleep" process ok (and asynctask executed every time).

can lend me hand?

ps: main activity (homeactivity) launches fragments. main activity has 2 drawers: left drawer visible, , right drawer visible when launching fragmentmapa (the fragment i'm showing right now). might issue due drawer behaviour?

thank much

solved. faces problem, check following post: https://stackoverflow.com/a/3291713/828551.

you must create interface, create instance of within asynctask , implement interface main class launch asynctask.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -