2012-03-02 2 views
1

다음 코드는 AsyncTask를 사용하여 비디오를 다운로드합니다.Android 진행 대화 상자 클래스 파일의 메시지 설정

//DOWNLOAD VIDEOS 
private class downloadVideosAsync extends AsyncTask <String, String, String>{ 

    protected void onPreExecute(){ 
     super.onPreExecute(); 
     MyActivity.this.mProgressDialog.setMessage("Downloading Videos..."); 
    } 

    @Override 
    protected String doInBackground(String... strings){ 
     try{ 

      VideosC.downloadVideos(VideosM.getVideoNames(), VideosM.getVideoUrls(), 
            VideosM.getVideoThumbs(), VideosM.getFileModified()); 

     }catch (NullPointerException e){ 
      Log.e(LOG_TAG, e.toString()); 
     }catch(Exception e){ 
      Log.e(LOG_TAG, e.toString()); 
     } 
     return null; 
    } 

    @Override 
    protected void onPostExecute(String lenghtOfFile) { 
     new downloadSlideshowsAsync().execute(); 
    } 
} 

본인의 진행률 대화 상자에 '동영상 다운로드 중 ...'메시지가 표시됩니다. 이제 내가하고 싶은 것은 setMessage ("Downloading of 5")와 같은 것입니다. 하지만 문제는 내 downloadVideos 함수가 다른 클래스 파일에 있습니다. VideosController.java

public void downloadVideos(ArrayList<String> VideoNames, ArrayList<String> VideoUrls, 
           ArrayList<String> VideoThumbs, ArrayList<String> fileModified){ 

    try{ 
     int x; 
     int videoNamesLenght = VideoNames.size(); 
     File vidFile; 
     for(x = 0; x < videoNamesLenght; x++) { 

      String[] videoName = VideoNames.get(x).split("/"); 
      String currentFile = videoName[0] + "." + videoName[1]; 
      String currentFileURL = VideoUrls.get(x) + VideoNames.get(x); 
      Log.v(LOG_TAG, "currentFileURL: " + currentFileURL); 

      vidFile = new File(Environment.getExternalStorageDirectory() 
           + "/MyApp/Downloads/Videos/", currentFile); 

        //I want to do maybe here something like 
        //mProgressDialog.setMessage("Downloading x of y") 

      downloadVideoFile(currentFile, currentFileURL, vidFile, fileModified.get(x)); 

     } 
    }catch(Exception e){ 
     Log.e(LOG_TAG, e.toString()); 
    } 
} 

아이디어가 있으십니까? 어떤 도움을 주셔서 감사합니다! :)

답변

1

Activity에서 VideosController를 호출하는 정적 함수를 정의 할 수 있습니다. 이 함수에서 핸들러 메시지를 보내고 처리 할 수 ​​있습니다.

+0

답장을 보내 주셔서 감사합니다. @rafeal piao. 그러나 샘플 코드가 있습니까, 실제로는 초보자입니다. :) – MiD

+0

죄송합니다. 내 손에 샘플이 없습니다. –

+0

VideosController를 호출 할 때 컨텍스트 개체를 전달할 수 있습니다. 컨텍스트에서 정적 함수를 방문 할 수 있습니다. onPostExecute 메서드에서이 코드를 설정하십시오. –