I don't need threads, I just want to increment the value of the progress bar manually by clicking a button.
Here's the XML code
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
And in the Java file I have
ProgressBar pb;
...
pb = (ProgressBar)findViewById(R.id.progressBar1);
pb.setMax(100);
pb.setProgress(0);
Now in a method that is called when a button is clicked, I want to increment the progress by one
public void increment(View view) {
int progress = pb.getProgress();
pb.setProgress(progress++);
}
This causes the program to crash. How can I control the ProgressBar from the Java program like this?