Implementando onClick

pessoal sou iniciante em programação e to como seguinte problema. Tenho um array de string e gostaria de mostrar as mensagens da string uma a uma cada vez que pressionar o botão “próximo”.

Você pode criar uma Activity +/- assim:

public class MyActivity extends Activity {
    // Variavel para controlar os clicks
    private int count = 0;
    // Variavel do Button
    private Button button;
    // Array de Strings
    private String[] toppings = {"Cheese", "Pepperoni", "Black Olives"};

    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // Set Layout
        setContentView(R.layout.idDoLayout);

        // Obtem o Button pelo findViewById
        button = (Button) findViewById(R.id.idDoButton);

        // Função para o Click do Button
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Quando clicar ...
                
                if (count == toppings.length) {
                    Toast.makeText(MyActivity.this, "Final do Array. Começar novamente", Toast.LENGTH_SHORT).show();
                    count = 0;
                } else {
                    // Mostra a string com o indice count
                    Toast.makeText(MyActivity.this, toppings[count], Toast.LENGTH_SHORT).show();

                    ++count; 
                    // Acrescenta 1 a varial conut para mostrar outra string no proximo click
                }
                
            }
        });
    }
}

Espero ajudar :slight_smile: