2017-10-13 2 views
1

내 프로젝트는 PDF를 다운로드하여보고 있습니다. https://stackoverflow.com/a/24748227/8769785단추를 진행하는 과정을 보여주는 프로세스 단추를 어떻게 추가합니까?

내가 다운로드 버튼의 다운로드 진행 상황을 보여주고 싶어요!

enter image description here

http://blog.rhesoft.com/2015/12/29/tutorial-android-process-button-animated-buttons-on-android-studio/

I [URL 제공에서 버튼을 다운로드 "다운로드" "보기"버튼을 눌러 파일을 열어] 파일 다운로드 중 (진행 상황) "다운로드 버튼"에 "프로세스 요청 제출"애니메이션을 추가하려고합니다.

내 문제는 다운로드 버튼에서 애니메이션 (진행률)을 얻는 방법을 모르겠다는 것입니다.

프로젝트에 "Filedownloader"클래스가 있습니다 기본 활동의 클릭 수신기에서 시도했지만 버튼에 진행률을 아직 얻을 수 없습니다. URL에서 진행할 수 없습니다.
Android 프로그래밍이 처음입니다. ;

코드처럼이

// 버튼 뷰 SubmitProcessButton btnSubmit = (SubmitProcessButton) findViewById를 (R.id.btnSubmit)을 얻을 수있다

//start with progress = 0 
    btnSubmit.setProgress(0); 

    //to test the animations, when we touch the button it will start counting 
    btnSubmit.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      SubmitProcessButton btn = (SubmitProcessButton) view; 
      // we add 25 in the button progress each click 
      if(btn.getProgress() < 100){ 
       btn.setProgress(btn.getProgress() + 25); 
      } 
     } 
    }); 
+1

서버에서 데이터를 다운로드하는 동안 진행 상황을 표시하기 위해 'AsyncTask'를 사용하십시오. –

+0

프로젝트에는 파일 다운로드에 도움이되는 filedownloader 클래스가 있습니다. 나는 setprogress를 어디에 추가 할 지 모르겠습니다. –

+0

대화 상자 또는 텍스트 뷰 사용, 진행 상황 추적 및 값 업데이트는 해결책이 될 수 있습니다. – rmjoia

답변

0

ProgressBar를 사용하면 다운로드 진행 상황을 표시 할 수 있습니다.

public class MainActivity extends ActionBarActivity { 
Button b1; 
private ProgressDialog progress; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    b1 = (Button) findViewById(R.id.button2); 
} 

public void download(View view){ 
    progress=new ProgressDialog(this); 
    progress.setMessage("Downloading Music"); 
    progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 
    progress.setIndeterminate(true); 
    progress.setProgress(0); 
    progress.show(); 

    final int totalProgressTime = 100; 
    final Thread t = new Thread() { 
    @Override 
    public void run() { 
     int jumpTime = 0; 

     while(jumpTime < totalProgressTime) { 
      try { 
       sleep(200); 
       jumpTime += 5; 
       progress.setProgress(jumpTime); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    } 
    }; 
    t.start(); 
    } 
} 
관련 문제