lundi 21 janvier 2019

How to increment a TextView in Android

Everytime my ProgressBar reaches 100, I want the number in displayed in textView2 to go up by one, and then the ProgressBar resets to 0, and it continues - 2, 3, 4 etc - so basically when the ProgressBar reaches 100, the level goes up by 1 which is displayed in textView2.

But, textView2 only goes up to 1, then the ProgressBar obviously resets to 0, and the process continues, except the textView2 does not display 2 or 3 etc.

My code at the moment makes textView2 go from 0 to 1 when the ProgressBar reaches 100, and then the ProgressBar resets, but when it's full again, textView2 does not change to 2.

So basically I want my textView2 to increment every time the ProgressBar reaches 100.

if (levels.getProgress() == 100) {

                try {
                    double d = Double.valueOf(String.valueOf(ph.getText()));
                    textView2.setText(String.valueOf( (int) d));
                    levels.setProgress(0);
                } catch (NumberFormatException e){
                    Toast.makeText(MainActivity.this, "Enter valid number.", Toast.LENGTH_SHORT).show();
                }
            }

Aucun commentaire:

Enregistrer un commentaire