title: Android: looping between text on button click
body: <p>I want to switch between 3 different strings when a button is pressed in a loop.</p>
  
  <p>I have put the text in a string array but i am not sure what to use to loop the array.</p>
  
  <pre><code>    Button ranFw = (Button) findViewById(R.id.ranButFw);
      final TextView ranTx = (TextView) findViewById(R.id.ranText);
  
  
  
      String[] rangeTx = new String[2];
      rangeTx[0]="0 to 1700C";
      rangeTx[1]="32 to 3218F";
      rangeTx[2]="273.15 to 1973.15K";
  
      ranFw.setOnClickListener( new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
          }
      });
  </code></pre>
  
  <p>Thanks steve</p>
  
  <p>Update:</p>
  
  <p>ranFw = (Button) findViewById(R.id.ranButFw);
          final TextView ranTx = (TextView) findViewById(R.id.ranText);</p>
  
  <pre><code>     final String[] rangeTx = new String[3];//String[2] means index from 0 to 1
      rangeTx[0] = "0 to 1700C";
      rangeTx[1] = "32 to 3218F";
      rangeTx[2] = "273.15 to 1973.15K";
      ranFw.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              switch (index) {
                  case 0:
                      // if we are using index 0, set the text to index 1 text and change index to 1
                      index = 1;
                      ranTx.setText(rangeTx[index]);
                      break;
                  case 1:
                      index = 2;
                      ranTx.setText(rangeTx[index]);
                      break;
                  case 2:
                      index = 0;
                      ranTx.setText(rangeTx[index]);
                      break;
  
              }
  
          }
  
      });
  </code></pre>
  
  <p>No errors but seems to be working properly</p>