2011-07-04 138 views
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; 
     } 

回答