Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Mark Junge
Mark Junge
1,374 Points

I want to refresh textView only 4 times in same activity.

How can i get this code to get the start again method 3 times (3 clicks) and the finishQuestions method in the last time (last click).

I have tried for two days now, cant break the loops. No mater how i do it fail. Either it keep getting the startAgain every time i click (non stopable), or it never show the activity that should be refreshed and stopped after four times (back to last activity (StartPlayActivity))

This is what i have in my oncreate method.

View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { startAgain(); } }; mTrueButton.setOnClickListener(listener); mFalseButton.setOnClickListener(listener);

public void startAgain() {
    Random randomGenerator = new Random();
    int randomNumber = randomGenerator.nextInt(questions.length);
    String[] block5 = {questions[randomNumber]};
    // mRepeatingTextview.setText(block5[0]);

public void finishQuestions(){
    Intent intent = new Intent(this, StartPlayActivity.class);

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Remember that variables declared inside a method are local to that method and are always wiped out when the method is done and created anew the next time it's called. If you want to keep track of how many times the button has been pressed, you'll have to store that outside the function.