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!

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

Android Build a Simple Android App Improving Our Code Simple Refactoring: Using a New Class

Niclas A
Niclas A
907 Points

Delete fact after used


Is it possible to make the app delete the fact, that is randomly selected, after it have been used, so you avoid getting the same fact multiple times?

Thanks in advance.

1 Answer

Damian Adams
Damian Adams
21,351 Points

You technically could if you wanted to, but if you "delete" it from your data structure then you will not be able to use it until you go on ahead and declare a new instance of your FactBook class. A better way to implement this "non-repeating" fact feature would be to store the previous fact in a member variable and then modify your random number generator to generate a new random number if the number that it generated is equal to the previous fact's array number.

This way you can get a fresh fact with each button tap, but you also keep all your fact data intact in your array.