我是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();
}
}