Progress bar increment

I want my progress bar to increase each time by 1 with maximum value 5 with same button click here is my code in button click

        ProgressBarQuestion.setMax(5);
        ProgressBarQuestion.setProgress(1);
        int progress = ProgressBarQuestion.getProgress();
        Log.e("PROGRESS", String.valueOf(progress));
        ProgressBarQuestion.setProgress(progress++);

but the problem is it increase by 1 on first click then its stop increasing.

Upvotes: 1

Views: 5294

Answers (6)

Murtaza Khanjiwala
Murtaza Khanjiwala

Reputation: 1

You are initializing the progressBar to 1 and then incrementing it by 1 every time so on the first click it would increment to 2 and then every time it would set it to 1 and then increment it to 2. So just shift setProgess function line to somewhere else.

Upvotes: 0

Bhupat Bheda
Bhupat Bheda

Reputation: 1978

try this

//declare global
int count = 0;
 ProgressBarQuestion.setMax(5);
 ProgressBarQuestion.setProgress(0);
//in on click

onClick(){
if(count<5){
  count++;
  ProgressBarQuestion.setProgress(count);
}

}

Upvotes: 0

Priyank Patel
Priyank Patel

Reputation: 12382

Initialize your progress bar and set max at out side of button click

ProgressBarQuestion.setMax(5);
ProgressBarQuestion.setProgress(1); 

And only setProgress on button click as below.

@Override
public void onClick(View v) {               
    int progress = ProgressBarQuestion.getProgress();
    Log.e("PROGRESS", String.valueOf(progress));
    ProgressBarQuestion.setProgress(progress++);
}

Upvotes: 0

Sayantan Roy
Sayantan Roy

Reputation: 134

Please initialize your counter outside the function. A static integer should be incremented and passed onto your current calling function.

only use this in your function!!

ProgressBarQuestion.setProgress(progress++);

and set progress outside your function

Upvotes: 0

Turtle
Turtle

Reputation: 1656

Are you sure you aren't calling ProgressBarQuestion.setProgress(1);everytime?

Upvotes: 0

Denny
Denny

Reputation: 1783

Do the initialization somewhere else ONCE

ProgressBarQuestion.setMax(5);
ProgressBarQuestion.setProgress(1);

Each time you click, you reset the progress back to 1 so it doesn't go up

Upvotes: 1

Related Questions