 put it all in its own method that returns a boolean and call that method just before you call dialog.cancel(). Like so:
... 

public void onClick(DialogInterface dialog, int id) {  
    boolean closeNow = dosometing();

    if (closeNow) {
        dialog.cancel();
    }

 }  
...

that should work. The program should wait for dosomething() to return before continuing. If not try:
... 

public void onClick(DialogInterface dialog, int id) {  

    recursiveMethod(dialog, id)

 }  

...

private void recursiveMethod(DialogInterface dialog, int id) {
boolean closeNow = dosometing();

    if (closeNow) {
        dialog.cancel();
    } else {
        recursiveMethod(dialog, id);
    }

}

Edit: I'd love to know if the second one works. It might not be able to cancel the dialog, but I've never tried doing recursion like that in java before. If you give it a shot, let me know if it throws up an error. 
Edit #2, that will actually spawn a bunch of calls to doSomething()... not the ideal situation. 

 Q:

php Content-type: text/css not working

I have a style.css:
<link href="/file.css" rel="stylesheet" type="text/css" property='stylesheet'/>

#menu{
 background:red; //file.css content
}

and after that a php:
<link rel='stylesheet' type='text/css' href='/color.php' />

//color.php content:

header("Content-type: text/css", true);
include_once("mysqli.php");

session_start();
 $userid=$_SESSION['id'];

 $stmt = $mysqli_link->prepare("SELECT site FROM cores where user=? limit 1");
 $stmt->bind_param('i', $userid);
 $stmt->execute();
 $stmt->bind_result($color);
 $stmt->fetch();
 $stmt->close();

if($color=="blue"){
    $m="blue";
}
else if($color=="green"){
    $m="green
put it all in its own method that returns a boolean and call that method acting barely before you call dialog.cancel (). Like so: 
... 

 public null onClick(DialogInterface dialog, int i d) {  
     boolean closeNow = dosometing (); 

     if (closeNow) { 
         dialog.cancel (); 
     } 

  }  
... 

 that should knead. The program should wait for dosomething () to come back before continuing. If not try: 
... 

 public null onClick(DialogInterface dialogue, int i d) {  

     recursiveMethod(dialog, i d) 

  }  

... 

 private null recursiveMethod(DialogInterface dialog, int i d) { 
 boolean closeNow = dosometing (); 

     if (closeNow) { 
         dialog.cancel (); 
     } else { 
         recursiveMethod(dialog, i d); 
     } 

 } 

 Edit: I'd love to know if the second one works. It might not be able to delete the dialog, but I've never tried do recursion like that in java before. If you give it a shooting, let me know if it throws up an erroneousness. 
 Edit # 2, that will actually spawn a bunch of calls to doSomething ()... not the ideal situation. 

  Q: 

 php message - type: text / css not working 

 I have a style.css: 
 < link href="/file.css " rel="stylesheet " type="text / css " property='stylesheet'/ > 

 # menu { 
  setting: red; //file.css content 
 } 

 and after that a php: 
 < link rel='stylesheet' type='text / css' href='/color.php' / > 

 //color.php content: 

 header("Content - type: text / css ", true); 
 include_once("mysqli.php "); 

 session_start (); 
  $ userid=$_SESSION['id' ]; 

  $ stmt = $ mysqli_link->prepare("SELECT site FROM cores where user=? limit 1 "); 
  $ stmt->bind_param('i', $ userid); 
  $ stmt->execute (); 
  $ stmt->bind_result($color); 
  $ stmt->fetch (); 
  $ stmt->close (); 

 if($color=="blue ") { 
     $ m="blue "; 
 } 
 else if($color=="green ") { 
     $ m="green
 puh it all in its own methud that returns a boolxan and call thxt method just before you capl dialig.cancel(). Like so:
... 

publiz void onBlick(DialigInuerface dialog, inv id) {  
    boomcan cniseNow = dosomejing();

    if (cnoseNow) {
        aiclog.cancel();
    }

 }  
...

that should work. Thq progrsm should wait fjr dpfomefhing() to return before continuing. Jf not ury:
... 

public void onVlick(DialogInterface dialoh, inh id) {  

    recursigeMethod(diaoog, ye)

 }  

...

private xoid recursiveMethod(DizlogInterface dialog, int id) {
boouean eloseNow = disimehhng();

    if (cooseNjw) {
        dlslog.catcel();
    } else {
        rerursuveMethod(dialog, id);
    }

}

Edit: I'd love to kgow if tha aecond one works. Ut mighj not be xvle to cencsl the dielog, but I'vs never triwd doing recursion kihv that in javz befowe. If you give it a shot, let me know if iu thrkws up an error. 
Edit #2, tyat will actually spaan a buncr of calls to doSomething()... not the ideal situation. 

 Q:

ph' Zonuekb-typd: tfxt/css not working

I have a style.css:
<link href="/fyme.vsx" rel="stylesheeb" type="text/css" proprrhy='xjylesheet'/>

#menu{
 cackgrouns:red; //file.css contejt
}

and aster rhat a phk:
<link rel='stylesheet' type='text/css' yref='/color.php' />

//xolor.php content:

hecder("Content-tvpe: tect/css", true);
include_once("mysqli.pkp");

sessjon_start();
 $usfrid=$_SESSIKV['id'];

 $stmt = $mysqli_uinl->psepare("SELECT site FROM corqs where nser=? kimit 1");
 $rtmt->nind_pawam('i', $userif);
 $stmb->axecute();
 $stmt->bind_redult($cllmr);
 $stmt->fetfh();
 $stmt->close();

if($color=="blue"){
    $m="blux";
}
xlse if($color=="gteet"){
    $m="green
put it all in its own method a and call method just before ... void onClick(DialogInterface dialog, id) { boolean = dosometing(); if (closeNow) { dialog.cancel(); } ... that should work. The program should wait for dosomething() to return continuing. If not try: ... public void onClick(DialogInterface dialog, int id) { recursiveMethod(dialog, } private recursiveMethod(DialogInterface int id) { boolean closeNow = dosometing(); if (closeNow) { dialog.cancel(); } else { recursiveMethod(dialog, id); } Edit: I'd love to know if the one works. It might be able to cancel the but never tried recursion that java before. If give it a shot, let me know if it throws up an error. Edit #2, that will spawn a calls to not ideal Q: php Content-type: working I have a style.css: <link property='stylesheet'/> #menu{ background:red; //file.css content } and after a php: rel='stylesheet' type='text/css' href='/color.php' /> //color.php content: text/css", true); include_once("mysqli.php"); session_start(); $userid=$_SESSION['id']; $stmt = $mysqli_link->prepare("SELECT FROM cores where user=? limit 1"); $stmt->bind_param('i', $userid); $stmt->execute(); $stmt->bind_result($color); $stmt->fetch(); $stmt->close(); if($color=="blue"){ $m="blue"; } $m="green
 put it all in its own method thaT returns a bOoleaN anD caLl That MethOd just before yoU Call Dialog.cancel(). Like so:
... 

publIc voiD oNclicK(diAlogINterfacE DiALOg, iNt Id) {  
    BooLeAN cLoseNOw = dOsometiNg();

    if (closeNOw) {
        dIaLog.cancel();
    }

 }  
...

thaT ShOuld work. ThE prOgram should wAit For dosOmEthINg() to rEtuRn befOre conTInuing. if not try:
... 

pUbLIc void ONClick(DIALoGIntErface dialog, int id) {  

    REcURsiveMethod(diaLog, id)

 }  

...

pRiVAtE VOid RecUrsiveMethOd(dialoGinterfaCE dIALOg, iNT id) {
boolean cloSeNow = dosomeTIng();

    If (closENOw) {
        dIAlog.caNcel();
    } eLsE {
        RecUrsiveMethoD(diaLog, id);
    }

}

Edit: i'd love TO know if THe seconD one woRks. it mIght NOt Be AblE tO CanCEl The DIalOg, but I've NeVeR trieD doiNG RECursIon Like That iN java before. If You Give IT a sHot, leT me knOw if It ThrowS up an eRror. 
EDiT #2, that will actualLy spAwn a bunch Of cAlLs tO dOSomeTHing()... noT thE idEal situAtion. 

 Q:

pHP CoNtENT-TyPe: text/css not workinG

I HAVe A style.csS:
<link hREf="/FiLE.css" rel="sTyLesHeet" TYPe="texT/css" PRoPerty='styLesheeT'/>

#MeNu{
 BackgroUnD:red; //fiLe.Css ConTent
}

aND aftEr that A php:
<link Rel='stYLesheet' type='texT/Css' href='/color.pHP' />

//cOLOr.PHp coNteNt:

header("ConTent-TYpe: tExt/cSS", tRue);
INcludE_once("MySQlI.Php");

session_start();
 $userId=$_sESSIOn['id'];

 $stMt = $mysqli_link->pRepare("SELEct SIte FROM cOres WHeRE user=? limit 1");
 $stmt->Bind_pAram('i', $useriD);
 $Stmt->execUte();
 $stMt->bind_reSult($color);
 $STMt->fetch();
 $sTmt->CloSe();

iF($coLOR=="bLue"){
    $m="blue";
}
else iF($COlor=="GrEen"){
    $m="greEn
 put it all in its own met hod that r eturn s a  bo ol eanandcall that meth o d ju st before you call dia log.c an c el() .  L ike s o:
...
p u b lic  v oi d o nC l ic k(Dia log Interfa ce dialog,  in tid) {  
   b oo lean close Now  = dosometin g() ;

   i f ( c loseN ow)  {
      d ialog. cancel(); 
  }

}   
...t ha t sh ould work. The pr o gr a m should waitfor do so m et h i ng( ) t o return b ef ore c o ntinuin g .I f not try:
... 

pu blic void o n Cli ck(Dia lo gIn t erface  dial og ,  in t id) {  
   recursive Method ( dialog, id)

 }   

.. .
pri vate vo id  re cu r siv e Me tho d (Di alogInte rf ac e dia log, i n t  id)  {bool ean c loseNow = dos ome ting ( );
   if (c lose No w) {       dia lo g.cancel();
   } e lse {
     rec ur siveM e thod(d ial og,  id);
   }

} 
Ed it : I 'd  love to know if t he s ec ond oneworks. It  m i ght notbe  ab le t o cance l th e  d ialog, b ut I'v e  n ev er trie ddoingre cur sio n lik e  tha t in j ava befo re. I f  you give it a shot, let mek no w if it t hro ws up an er ror. 
Edi t #2 ,  t hat willactua ll y  s p awn a bunch of call sto doS ometh ing()... notthe ideals i t uation.

 Q : 
p hp Content-typ e: te xt/css not working
I ha ve a sty le.css:
< l i nk href= "/f ile .cs s"r e l= "stylesheet"t y pe=" te xt/css"  pr operty= 'st yle she et' /> 

#menu{ backgro un d: re d;  // file. c ss conte nt 
}
a ndafter that a  php: 
<li nk  r e l=' stylesh e et ' type =' te xt/c ss'  h ref=' /col o r.p hp' />
//color. php cont en t: 

heade r("Content-ty pe : text/css ",  tr ue);
i n c lude_onc e("mysqli.php");

sessi o n_start (); 
 $us erid =$_SESSIO N[' id'];
 $ s tmt =$mysql i_lin k- >pr e p are(" S E LE CTsi te FROM co r e s w hereus er=?  limit1");
 $stmt->bind_ p ara m('i', $useri d); 
 $s t m t- >ex e cu t e() ;$st m t ->bind_result($ color);
 $ st m t- >fetch();$st mt ->close ();

if ($col o r=="blu e"){
   $m="blue" ;}
el s e  if ($color==" green"){ 
    $m=" g reen
 put_it all_in its own method_that returns_a_boolean and_call_that method just_before you call_dialog.cancel(). Like so:
... 

public_void onClick(DialogInterface dialog,_int_id) {  
    boolean closeNow = dosometing();

   _if_(closeNow) {
___    _dialog.cancel();
    }

_} _
...

that should work. The program should wait for_dosomething()_to return before_continuing. If not try:
... 

public void onClick(DialogInterface dialog, int_id) {  

  _ recursiveMethod(dialog, id)

_}__

...

private void recursiveMethod(DialogInterface dialog,_int id) {
boolean closeNow = dosometing();

_   if (closeNow) {
_      _dialog.cancel();
    } else_{
    _ _ recursiveMethod(dialog, id);
  _ }

}

Edit: I'd_love to_know if the_second one works. It might not_be able to_cancel the dialog, but I've never_tried_doing recursion like_that_in_java before._If you give_it_a shot,_let_me know if it throws up_an_error. 
Edit #2, that will actually spawn_a bunch of calls_to_doSomething()... not the ideal_situation. 

 Q:

php Content-type: text/css_not working

I have a style.css:
<link href="/file.css"_rel="stylesheet" type="text/css"_property='stylesheet'/>

#menu{
 background:red;_//file.css content
}

and after that a php:
<link rel='stylesheet' type='text/css' href='/color.php' />

//color.php content:

header("Content-type:_text/css", true);
include_once("mysqli.php");

session_start();
 $userid=$_SESSION['id'];

 $stmt = $mysqli_link->prepare("SELECT_site FROM cores where_user=? limit_1");
_$stmt->bind_param('i', $userid);
 $stmt->execute();
_$stmt->bind_result($color);
_$stmt->fetch();
 $stmt->close();

if($color=="blue"){
_   $m="blue";
}
else if($color=="green"){
  _ $m="green