1
As you can see in the code, when I click I’m randomly defining the phrase, but when I click, I want the phrase that I myself define through the indexes, how do I do this?
Public class MainActivity extends AppCompatActivity {
private TextView textoNovaFrase;
private Button botaoNovaFrase;
private String[] frases = {
"Se você traçar metas absurdamente altas e falhar, seu fracasso será muito melhor que o sucesso de todos",
"O sucesso normalmente vem para quem está ocupado demais para procurar por ele",
"Se você não está disposto a arriscar, esteja disposto a uma vida comum"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textoNovaFrase = (TextView) findViewById(R.id.textoNovaFraseId);
botaoNovaFrase = (Button) findViewById(R.id.botaoNovaFraseId);
botaoNovaFrase.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random randomico = new Random();
int numeroAleatorio = randomico.nextInt( frases.length );
textoNovaFrase.setText( frases[ numeroAleatorio ] );
}
});
The question got confused for me, can explain better what you want to do?
– CloudAC
When I click on the phrase botaonovafrase, it will generate a sentence, but now I do not want it to be random, I want to know which sentence I will come from, I have three sentences there, I want to put all three in order, when I click on the phrase botanovafrase, it will generate the first sentence, when I click again, will generate the second sentence, and clicking again will generate the third sentence, how to do this?
– L.jack