0

我使用本教程创建自定义进度条,它可以工作。

但是我想在进度条达到 100% 时开始新的活动。

任何人都可以帮助将开始新的活动代码放在正确的位置吗?

4

3 回答 3

4

您可以在设置时检查进度是否已达到最大值,如下所示:

@Override
  public synchronized void setProgress(int progress) {
    super.setProgress(progress);

    // the setProgress super will not change the details of the progress bar
    // anymore so we need to force an update to redraw the progress bar
    invalidate();

    if(progress >= getMax()) {
        Intent intent....
    }
  }
于 2012-09-21T15:29:22.793 回答
1

您可以调用 onContinue 函数计时器线程并将意图设置为下一个活动并在清单文件中注册活动名称。

@Override
   public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress);
    mProgressBar = (ProgressBar)findViewById(R.id.adprogress_progressBar);
    final Thread timerThread = new Thread() {
        @Override
            public void run() {
            mbActive = true;
            try {
                int waited = 0;
                    while(mbActive && (waited < TIMER_RUNTIME)) {
                        sleep(200);
                        if(mbActive) {
                            waited += 200;
                            updateProgress(waited);
                        }
                    }
            } catch(InterruptedException e) {
        } finally {
                onContinue();
        }
      }
    };
    timerThread.start();
}
@Override
public void onDestroy() {
    super.onDestroy();
}
public void updateProgress(final int timePassed) {
    if(null != mProgressBar) {
        final int progress = mProgressBar.getMax() * timePassed / TIMER_RUNTIME;
        mProgressBar.setProgress(progress);
    }
}

public void onContinue() {
    Intent intd=new Intent(this,MainActivity.class);
    startActivity(intd);
    }
于 2014-01-23T12:35:20.730 回答
0

试试这个...

new Thread(new Runnable() {
    public void run() {
        while (progressStatus < 100) {
            progressStatus += 5;
            // Update the progress bar and display the current value in the text view
            handler.post(new Runnable() {
                public void run() {
                    progressBar.setProgress(progressStatus);
                    textView.setText("Loading "+progressStatus+"/"+progressBar.getMax());
                }
            });
            try {
                // Sleep for 200 milliseconds. Just to display the progress slowly
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }

    **Intent intent = new Intent(Main_Activity.this, Send_Email.class);
        startActivity(intent);**
    }
}).start();
于 2014-11-26T15:56:55.070 回答