EDIT: JUST REALISED I POSTED THIS IN V2 THREAD. I MEANT TO POST IT IN THE V1 THREAD SORRY
Thanks for this! I have had to make a few fixes to it to get it to work.
I have marked all my changes with "//Fixed"
I also notice you are calling your main activity one thing and then changing it to another (could be confusing for some

- Code: Select all
//........................................................
//Fixed not sure what was going on with the dialogue, so i wrote one.
//........................................................
private void browseTo(final File aDirectory){
if (aDirectory.isDirectory()){
this.currentDirectory = aDirectory;
fill(aDirectory.listFiles());
}else{
OnClickListener okButtonListener = new OnClickListener(){
// @Override
public void onClick(DialogInterface arg0, int arg1) {
try {
// Lets start an intent to View the file, that was clicked...
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("file://"
+ aDirectory.getAbsolutePath()));
startActivity(myIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
};
doDialogue(this,"Question","Do you want to open that file?\n"
+ aDirectory.getName(),
"OK", "Cancel",
okButtonListener);
}
}
//........................................................
//Added this method. Now dialogue is reusable.
//........................................................
private void doDialogue(Context context, String title, String message, String positivetext, String negativetext,OnClickListener okButtonListener){
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(Html.fromHtml( title ));
dialog.setMessage(Html.fromHtml(message));
dialog.setPositiveButton(positivetext, okButtonListener);
dialog.setNegativeButton(negativetext, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.show();
}
//........................................................
//Fixed files comes up as null when browsing system folder
//........................................................
private void fill(File[] files) {
this.directoryEntries.clear();
if (files==null){
files = new File[0];
}
// Add the "." and the ".." == 'Up one level'
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
this.directoryEntries.add(".");
if(this.currentDirectory.getParent() != null)
this.directoryEntries.add("..");
switch(this.displayMode){
case ABSOLUTE:
for (File file : files){
this.directoryEntries.add(file.getPath());
}
break;
case RELATIVE: // On relative Mode, we have to add the current-path to the beginning
int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();
for (File file : files){
this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLenght));
}
break;
}
ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this,
R.layout.file_row, this.directoryEntries);
this.setListAdapter(directoryList);
}
//........................................................
//Fixed getItem method not present, why not just use the ID available
//........................................................
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
int selectionRowID = (int) id;
String selectedFileString = this.directoryEntries.get(selectionRowID);
if (selectedFileString.equals(".")) {
// Refresh
this.browseTo(this.currentDirectory);
} else if(selectedFileString.equals("..")){
this.upOneLevel();
} else {
File clickedFile = null;
switch(this.displayMode){
case RELATIVE:
clickedFile = new File(this.currentDirectory.getAbsolutePath()
+ this.directoryEntries.get(selectionRowID));
break;
case ABSOLUTE:
clickedFile = new File(this.directoryEntries.get(selectionRowID));
break;
}
if(clickedFile != null)
this.browseTo(clickedFile);
}
}



because class File don't support much, but I 'll try. Thanks for tutorial, you're great
. 