我想创建一个按钮,使进度条完成后使程序移至另一个意图。我已经有了按钮和进度条的代码,但是我很困惑应该在哪里放置代码以移动到另一个意图。
btnIdentifikasi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pgsBar.setVisibility(View.VISIBLE);
txtView.setVisibility(View.VISIBLE);
i = pgsBar.getProgress();
new Thread(new Runnable() {
@Override
public void run() {
while (i < 100) {
i += 1;
hdlr.post(new Runnable() {
@Override
public void run() {
pgsBar.setProgress(i);
txtView.setText(i+"/"+pgsBar.getMax());
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e){
e.printStackTrace();
}
}
}
}).start();
}
});
}
public void openHasilIdentifikasi() {
Intent intent = new Intent(IdentifikasiActivity.this, MainActivity.class);
startActivity(intent);
}
答案 0 :(得分:0)
代码:
class Activityafterpb extends AsyncTask<Integer, Integer, String> {
@Override
protected String doInBackground(Integer... params) {
for (; count <= params[0]; count++) {
try {
Thread.sleep(1000);
publishProgress(count);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return "Finished";
}
@Override
protected void onPostExecute(String result) {
pgsBar.setVisibility(View.GONE);
openHasilIdentifikasi();
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Integer... values) {
pgsBar.setProgress(values[0]);
}
}
}