私はアンドロイドに新しいです、スレッドを管理する経験はあまりありません。私は、例えば5秒間進捗バーを表示し、その後繰り返すアクティビティに取り組んでいます。 5秒間、ユーザーがテキストを操作するためのテキストが表示されます。私はこれをN回繰り返す。Androidでの一連のタスクのProgressBarアクティビティの繰り返し
現在のところ、このような進捗状況の1つでは次のコードがあります。私はそれをループしようとしましたが、スレッドが同時に実行されるので、それは役に立ちませんでした。これを何回N回繰り返すことができますか?問題を解決するために私は正しい道にいるのですか?
public class test extends Activity {
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loop);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
textView = (TextView) findViewById(R.id.textView1);
progressBar.setScaleY(3f);
// Start long running operation in a background thread
for(int i=0; i<5; i++)
Progress();
}
public void Progress(){
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
// 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(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
//Just to display the progress slowly
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
'5秒間に、ユーザーがテキストを操作するためのテキストを表示します。 TextViewに表示されるテキストを操作するには?ユーザーは何をすべきですか? – greenapps
一度に5つのスレッドを開始しないでください。スレッドが完了すると、次のスレッドを開始します。または、run()のコードをループ内で5回実行させます。 – greenapps
ユーザーは5回進捗状況を見ているとはどういう意味ですか? – greenapps