根据网络呼叫和响应自定义循环进度条,其中包含进度状态

时间:2016-08-09 06:58:07

标签: java android android-layout android-studio android-fragments

我是Android新手,我正在尝试根据网络调用构建自定义循环ProgressBar。意思

1.当我点击Button时,ProgressBar应加载50%

2.当我收到服务器的响应时,必须加载其他50%来完成操作 提前谢谢你

这是我的Prog.java类

public class Prog extends Activity {

    private ProgressBar progBar;
    private TextView text;
    private Handler mHandler = new Handler();
    private int mProgressStatus=0;
    int load=0;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_prog);
      progBar= (ProgressBar)findViewById(R.id.progressBar);
      dosomething();

  }

  public void dosomething() {

      new Thread(new Runnable() {
          public void run() {
              final int presentage=0;
              while (mProgressStatus < 50) {
                  mProgressStatus += 1;
                  // Update the progress bar
                  mHandler.post(new Runnable() {
                      public void run() {
                          progBar.setProgress(mProgressStatus);


                      }
                  });
                try {

                    Thread.sleep(50);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

         }
        }).start();
    }

 }

1 个答案:

答案 0 :(得分:0)

以下链接正常工作并适用于ProgressBar倒计时

所以你可以尝试this