title: Android Studio for loop
body: <p>I Have the following code and want to find out if there is any way i can put the following code into a <code>for</code> loop so that it is not so long as i am doing it a few times in my code </p>
  
  <pre><code> if (Q1o1.equals("null")){
       button1.setVisibility(View.INVISIBLE); 
   }else{
       button1.setVisibility(View.VISIBLE);
       button1.setText(Q1o1);
   }
   if (Q1o2.equals("null")){
       button2.setVisibility(View.INVISIBLE);
   } else{
       button2.setVisibility(View.VISIBLE);
       button2.setText(Q1o2);
   }
   if (Q1o3.equals("null")){
       button3.setVisibility(View.INVISIBLE);
   } else{
       button3.setVisibility(View.VISIBLE);
       button3.setText(Q1o3);
   }
   if (Q1o4.equals("null")){
       button4.setVisibility(View.INVISIBLE);
   } else{
       button4.setVisibility(View.VISIBLE);button4.setText(Q1o4);
   }
   if (Q1o5.equals("null")){
       button5.setVisibility(View.INVISIBLE);
   } else{
       button5.setVisibility(View.VISIBLE);
       button5.setText(Q1o5);
   }
   if (Q1o6.equals("null")){
       button6.setVisibility(View.INVISIBLE);
   } else{
       button6.setVisibility(View.VISIBLE);
       button6.setText(Q1o6);
   }
   if (Q1o7.equals("null")){
       button7.setVisibility(View.INVISIBLE);
   } else{
       button7.setVisibility(View.VISIBLE);
       button7.setText(Q1o7);
   }
  </code></pre>
  
  <p>Every if statement checks if the relevant variable that needs to be the button text is not null and then either hides it or puts that variable inside the button and shows the button. How can i make a for loop using different variables for each loop?</p>