Code example for AlertDialog.Builder

Methods: setItems, setTitle, show

0
	  } 
	} 
 
	  protected Dialog onCreateDialog(int id){
	  Dialog dialog = null;
	  AlertDialog.Builder builder = new Builder(this);
 
	  switch(id){
	  case DIALOG_LOAD_FILE:
	   builder.setTitle("Choose your file");
	   if(mFileList == null){
	     //Log.e(TAG, "Showing file picker before loading the file list"); 
	     dialog = builder.create();
	     return dialog;
	   } 
	     builder.setItems(mFileList, new DialogInterface.OnClickListener(){
	       public void onClick(DialogInterface dialog, int which){
	          mChosenFile = mFileList[which];
	          mPath = new File(mPath.getAbsolutePath()+File.separatorChar+mChosenFile);
	  		if (mPath.isDirectory()) {
	  			loadFileList(); 
	  			Dialog a = onCreateDialog(DIALOG_LOAD_FILE);
	  			a.show();
			} 
	  			 
	  		 
	           
	          
	          //you can do stuff with the file here too 
	       } 
	      }); 
	  break; 
	  } 
	  dialog = builder.show();
	  return dialog;
	 }  
 
}