In one class I got a string with facts in an array like this:
public class FactBook {
public String[] mFacts = {"a", "b", "c"};
....
Now I got a random generator like this:
public String getFact() {
String fact = "";
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(mFacts.length);
fact = mFacts[randomNumber];
return fact;
}
My randomButton in the activity class is like this:
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
final Button showFactButton = (Button) findViewById(R.id.showFactButton);
final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
final MediaPlayer mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.button);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mMediaPlayer.start();
String fact = mFactBook.getFact();
//Update the Label with our dynamic fact
factLabel.setText(fact);
int color = mColorWheel.getColor();
relativeLayout.setBackgroundColor(color);
showFactButton.setTextColor(color);
}
};
showFactButton.setOnClickListener(listener);
Now I would like to create a button that goes through the array step by step (like a nextButton and previousButton). But I'm stuck. Does someone has any ideas?