Code example for AlertDialog.Builder

Methods: setAdapter, setTitle, show

0
		if (firstLvl == true)
			loadFileList(); 
		 
		Dialog dialog = null;
		int id = 1000;
		AlertDialog.Builder builder = new Builder(getActivity());
		 
		if (fileList == null) {
			Log.e(TAG, "No files loaded");
			dialog = builder.create();
			return dialog;
		} 
 
		//switch (id) { 
		//case DIALOG_LOAD_FILE: 
			builder.setTitle("Choose your file");
			builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
				@Override 
				public void onClick(DialogInterface dialog, int which) {
					chosenFile = fileList[which].file;Log.d("CHOSEN", chosenFile);
					File sel = new File(path + "/" + chosenFile);
					if (sel.isDirectory()) {
						firstLvl = false;
 
						// Adds chosen directory to list 
						str.add(chosenFile);
						fileList = null;
						path = new File(sel + "");
						loadFileList(); 
						FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
					    Fragment prev = getActivity().getFragmentManager().findFragmentByTag("dialog");
					    if (prev != null) {
					        ft.remove(prev);
					    } 
					    ft.addToBackStack(null);
					     
					    show(ft, "dialog");
						Log.d(TAG, path.getAbsolutePath());
 
					} 
 
					// Checks if 'up' was clicked 
					else if (chosenFile.equalsIgnoreCase("up") && !sel.exists()) {
 
						// present directory removed from list 
						String s = str.remove(str.size() - 1);
 
						// path modified to exclude present directory 
						path = new File(path.toString().substring(0,
								path.toString().lastIndexOf(s)));
						fileList = null;
 
						// if there are no more directories in the list, then 
						// its the first level 
						if (str.isEmpty()) {
							firstLvl = true;
						} 
						loadFileList(); 
						FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
					    Fragment prev = getActivity().getFragmentManager().findFragmentByTag("dialog");
					    if (prev != null) {
					        ft.remove(prev);
					    } 
					    ft.addToBackStack(null);
					     
					    show(ft, "dialog");
						Log.d(TAG, path.getAbsolutePath());
 
					} 
					// File picked 
					else { 
						// Perform action with file picked 
						 
						FileInputStream fIn;
						try { 
							fIn = new FileInputStream(sel);
							BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
							String aDataRow = "";
							String aBuffer = "";
							while ((aDataRow = myReader.readLine()) != null) {
								aBuffer += aDataRow + "\n";
							} 
							caldata = aBuffer;
							 
							myReader.close();
							 
							UploadScheduleAsynTask uploadSchedule = new UploadScheduleAsynTask(caldata);
							/*uploadSchedule.execute(); 
							try { 
								uploadSchedule.get(); 
							} catch (InterruptedException e) { 
								// TODO Auto-generated catch block 
								e.printStackTrace(); 
							} catch (ExecutionException e) { 
								// TODO Auto-generated catch block 
								e.printStackTrace(); 
							} 
							*/ 
							 
							System.out.println(uploadSchedule.isDone());
							 
							//if(uploadSchedule.isDone()){ 
								GetScheduleAsynTask getSchedule = new GetScheduleAsynTask("1", (FragmentActivity) getActivity());
								getSchedule.execute();
								 
							//} 
							 
								 
						 
						} catch (FileNotFoundException e) {
							// TODO Auto-generated catch block 
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block 
							e.printStackTrace();
						} 
					} 
					 
				} 
			}); 
			//break; 
		//} 
			 
		dialog = builder.show();
		return dialog;
	} 
	 
	public void loadFileList() { 
		try {