Reputation: 3
I can't seem to get my progress bar to update when the button is pressed. Here is how I have the code written.
mSubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double startingBudget = Double.parseDouble(mStartingBudgetInput.getText().toString());
mProgressBar.setMax((int)(startingBudget * 100));
double amountSpent = Double.parseDouble(mAmountSpentInput.getText().toString());
mProgressBar.incrementProgressBy(((int)(amountSpent * 100)) / ((int)(startingBudget * 100)));
Log.d("subButton", "onClick: " + startingBudget * 100);
}
});
Upvotes: 0
Views: 314
Reputation: 420
When your button is clicked, you can call ProgressBar
's setMax()
and then setProgress()
methods to show the progress.
Check if your progress bar XML is something like this
<ProgressBar
android:id="@+id/pb_products"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="6dp"/>
And call a method like this to update your progress in the progress bar
private void setProgressBar(ProgressBar progressBar, int progress, int max) {
progressBar.setMax(max);
progressBar.setProgress(progress);
progressBar.animate();
}
Upvotes: 1