0
申し訳ありませんが、ファイル選択ダイアログを作成しようとしています。ファイルを選択できるようにしましたが、ディレクトリを選択すると移動し、新しいディレクトリ。 今は、ディレクトリにヒットすると黒い画面に変わります。ディレクトリにヒットしたときにディレクトリのファイルを一覧表示するにはどうしたらいいですか? これは私がこれまでに得たコードです:Androidファイルのダイアログの煩わしさ
private void loadFileList(){
try{
dir.mkdirs();
}
catch(SecurityException e){
Log.e("Error: ", "unable to write on the 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 your 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 your 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 a name");
// Set an EditText view to get 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;
}