java - Android file dialog woes -
alright, i'm trying make file choice dialog, , got can choose file, want when choose directory moves , lists files in new directory. right goes black screen when hit directory. how make list directory's files when hit directory? code got far:
private void loadfilelist(){ try{ dir.mkdirs(); } catch(securityexception e){ log.e("error: ", "unable write on sd card " + e.tostring()); } if(dir.exists()){ mfilelist = dir.list(); } else{ mfilelist= new string[0]; } } protected dialog oncreatedialog(int id){ dialog dialog = null; alertdialog.builder builder = new builder(this); switch(id){ case dialog_load_rom: builder.settitle("choose rom"); if(mfilelist == null){ dialog = builder.create(); return dialog; } builder.setitems(dir.list(), new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int which){ mchosenfile = dir.list()[which]; rom = new file(dir, mchosenfile); if(rom.isdirectory()){ log.e("log:",dir.getabsolutepath()); dir = new file(dir, mchosenfile); log.e("log:",dir.getabsolutepath()); loadfilelist(); showdialog(dialog_load_rom); } else{ loadfilelist(); showdialog(dialog_load_patch); } } }); break; case dialog_load_patch: builder.settitle("choose patch"); if(mfilelist == null){ dialog = builder.create(); return dialog; } builder.setitems(dir.list(), new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int which){ mchosenfile = dir.list()[which]; file sdcard = environment.getexternalstoragedirectory(); patch = new file(sdcard, mchosenfile); alertdialog.builder alert = new alertdialog.builder(masterapp); alert.settitle("new rom name"); alert.setmessage("please input name"); // set edittext view user input final edittext input = new edittext(masterapp); alert.setview(input); alert.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { string value = input.gettext().tostring(); file sdcard = environment.getexternalstoragedirectory(); file newrom = new file(sdcard,value); patchrom(rom, patch, newrom); alertdialog.builder alert2 = new alertdialog.builder(masterapp); alert2.settitle("finished"); alert2.setmessage("rom has been patched"); alert2.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { system.exit(0); } }); alert2.show(); } }); alert.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { file sdcard = environment.getexternalstoragedirectory(); file newrom = new file(sdcard,"newrom.gb"); patchrom(rom, patch, newrom); alertdialog.builder alert2 = new alertdialog.builder(masterapp); alert2.settitle("finished"); alert2.setmessage("rom has been patched"); alert2.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { system.exit(0); } }); alert2.show(); } }); alert.show(); } }); break; } dialog = builder.show(); return dialog; }
take @ code.google.com/p/android-file-dialog/ source code. alternatively, can use it, not writing own
Comments
Post a Comment