title: Using loop in LinearLayout with textview and button in android studio using java
body: <p>**Im working in our thesis project, an Evaluation mobile app. And im having trouble to figure out on how I can make every textview have 5 buttons within so that evaluation could do. Or do i need something else to do what i wish for. Im asking for your great minds. Thank you.</p>
  <p>To be clear: Like I have a textview that says &quot;YOU ARE GOOD INSTRUCTOR&quot; with that there will be 5 button for evaluation like strongly agree, agree, neutral, disagree, and strongly disagree.**</p>
  <blockquote>
  <blockquote>
  <p>[YOU ARE GOOD INSTRUCTOR, TEACH WELL IN CLASS, MOTIVATE STUDENT TO DO WELL, UNDERSTAND STUDENT]</p>
  </blockquote>
  </blockquote>
  <p><strong>Example like: Every evaluation form in that array will have 5 buttons so a student can evaluation his/her instructor.</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.drawerlayout.widget.DrawerLayout
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:fitsSystemWindows=&quot;true&quot;
      android:id=&quot;@+id/drawer_layout&quot;
      android:layout_gravity=&quot;start&quot;
      tools:context=&quot;.User&quot;
      &gt;
  
     &lt;com.google.android.material.navigation.NavigationView
         android:layout_width=&quot;wrap_content&quot;
         android:layout_height=&quot;match_parent&quot;
         android:layout_gravity=&quot;start&quot;
         android:id=&quot;@+id/nav_view&quot;
         app:headerLayout=&quot;@layout/nav_header&quot;
         app:menu=&quot;@menu/drawer_menu&quot;/&gt;
     &lt;androidx.appcompat.widget.Toolbar
         android:id=&quot;@+id/toolbar&quot;
         android:layout_width=&quot;90dp&quot;
         android:layout_height=&quot;?attr/actionBarSize&quot;
         android:background=&quot;@color/white&quot;
         android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;
         app:popupTheme=&quot;@style/ThemeOverlay.AppCompat.Light&quot; /&gt;
  
     &lt;FrameLayout
         android:id=&quot;@+id/fragmentContainer&quot;
         android:layout_width=&quot;match_parent&quot;
         android:layout_height=&quot;672dp&quot; &gt;
  
        &lt;RelativeLayout
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            android:background=&quot;#F6F0F0&quot;
            tools:context=&quot;.User&quot;
  
            &gt;
  
           &lt;RelativeLayout
               android:id=&quot;@+id/header&quot;
               android:layout_width=&quot;match_parent&quot;
               android:layout_height=&quot;70dp&quot;
               android:background=&quot;#802626&quot;
               android:paddingLeft=&quot;15dp&quot;&gt;
  
              &lt;ImageView
                  android:id=&quot;@+id/menu_logo&quot;
                  android:layout_width=&quot;60dp&quot;
                  android:layout_height=&quot;60dp&quot;
                  android:layout_centerVertical=&quot;true&quot;
                  android:src=&quot;@drawable/ic_menu&quot; /&gt;
  
  
           &lt;/RelativeLayout&gt;
  
           &lt;TextView
               android:id=&quot;@+id/select&quot;
               android:layout_width=&quot;wrap_content&quot;
               android:layout_height=&quot;wrap_content&quot;
               android:layout_below=&quot;@+id/header&quot;
               android:text=&quot;Select: &quot;
               android:layout_marginTop=&quot;10dp&quot;
               android:layout_marginLeft=&quot;10dp&quot;
               android:textColor=&quot;@color/black&quot;
               android:textSize=&quot;24sp&quot; /&gt;
  
           &lt;Spinner
               android:id=&quot;@+id/faculty&quot;
               android:layout_width=&quot;200dp&quot;
               android:layout_height=&quot;wrap_content&quot;
               android:layout_below=&quot;@+id/header&quot;
               android:layout_marginLeft=&quot;20dp&quot;
               android:layout_marginTop=&quot;10dp&quot;
               android:layout_toRightOf=&quot;@+id/select&quot;
               android:theme=&quot;@style/Theme.Design.Light.NoActionBar&quot;
               android:visibility=&quot;visible&quot; /&gt;
  
           &lt;ScrollView
               android:id=&quot;@+id/body&quot;
               android:layout_width=&quot;match_parent&quot;
               android:layout_height=&quot;wrap_content&quot;
               android:layout_below=&quot;@+id/faculty&quot;
               android:layout_marginTop=&quot;20dp&quot;
               android:paddingBottom=&quot;80dp&quot;
              &gt;
              &lt;LinearLayout
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;
                  android:id=&quot;@+id/containerTable&quot;&gt;
  
  
                 &lt;LinearLayout
                     android:id=&quot;@+id/tableQuestions1&quot;
                     android:layout_width=&quot;match_parent&quot;
                     android:layout_height=&quot;wrap_content&quot;
                     android:orientation=&quot;vertical&quot;
                     android:layout_marginBottom=&quot;15dp&quot;
                     android:paddingLeft=&quot;10dp&quot;&gt;
  
                    &lt;TextView
                        android:id=&quot;@+id/question1&quot;
                        android:layout_width=&quot;wrap_content&quot;
                        android:layout_height=&quot;wrap_content&quot;
                        android:layout_centerHorizontal=&quot;true&quot;
  
                        android:textColor=&quot;@color/black&quot;
                        android:textSize=&quot;20sp&quot; /&gt;
  
                    &lt;LinearLayout
                        android:layout_width=&quot;wrap_content&quot;
                        android:layout_height=&quot;wrap_content&quot;
                        android:orientation=&quot;horizontal&quot;&gt;
                       &lt;androidx.appcompat.widget.AppCompatButton
                           android:id=&quot;@+id/xAgree1&quot;
                           android:layout_width=&quot;60dp&quot;
                           android:layout_height=&quot;40dp&quot;
                           android:layout_below=&quot;@+id/question1&quot;
                           android:layout_marginLeft=&quot;20dp&quot;
                           android:layout_marginRight=&quot;5dp&quot;
                           android:background=&quot;#52D15E&quot;
                           android:text=&quot;SA&quot; /&gt;
  
                       &lt;androidx.appcompat.widget.AppCompatButton
                           android:id=&quot;@+id/agree1&quot;
                           android:layout_width=&quot;70dp&quot;
                           android:layout_height=&quot;40dp&quot;
                           android:layout_below=&quot;@+id/question&quot;
                           android:layout_marginRight=&quot;5dp&quot;
                           android:layout_toRightOf=&quot;@+id/xAgree1&quot;
                           android:background=&quot;#6498EF&quot;
                           android:text=&quot;A&quot; /&gt;
  
                       &lt;androidx.appcompat.widget.AppCompatButton
                           android:id=&quot;@+id/neutral1&quot;
                           android:layout_width=&quot;70dp&quot;
                           android:layout_height=&quot;40dp&quot;
                           android:layout_below=&quot;@+id/question1&quot;
                           android:layout_marginRight=&quot;5dp&quot;
                           android:layout_toRightOf=&quot;@+id/agree1&quot;
                           android:background=&quot;#979BA1&quot;
                           android:text=&quot;N&quot; /&gt;
  
                       &lt;androidx.appcompat.widget.AppCompatButton
                           android:id=&quot;@+id/disagree1&quot;
                           android:layout_width=&quot;70dp&quot;
                           android:layout_height=&quot;40dp&quot;
                           android:layout_below=&quot;@+id/question1&quot;
                           android:layout_marginRight=&quot;5dp&quot;
                           android:layout_toRightOf=&quot;@+id/neutral1&quot;
                           android:background=&quot;#DCCC3D&quot;
                           android:text=&quot;DA&quot; /&gt;
  
                       &lt;androidx.appcompat.widget.AppCompatButton
                           android:id=&quot;@+id/xDisagree1&quot;
                           android:layout_width=&quot;70dp&quot;
                           android:layout_height=&quot;40dp&quot;
                           android:layout_below=&quot;@+id/question&quot;
                           android:layout_toRightOf=&quot;@+id/disagree&quot;
                           android:background=&quot;#DA4545&quot;
                           android:text=&quot;SDA&quot; /&gt;
                    &lt;/LinearLayout&gt;
                 &lt;/LinearLayout&gt;
  
              &lt;/LinearLayout&gt;
           &lt;/ScrollView&gt;
           &lt;Button
               android:layout_width=&quot;match_parent&quot;
               android:layout_height=&quot;wrap_content&quot;
               android:text=&quot;Submit&quot;
               android:background=&quot;#219EA8&quot;
               android:layout_marginLeft=&quot;10dp&quot;
               android:layout_marginRight=&quot;10dp&quot;
                 android:layout_alignParentBottom=&quot;true&quot;
               android:layout_marginBottom=&quot;6dp&quot;
               android:id=&quot;@+id/btnSubmit&quot;
               /&gt;
  
        &lt;/RelativeLayout&gt;
  
  
     &lt;/FrameLayout&gt;
  
  
  &lt;/androidx.drawerlayout.widget.DrawerLayout&gt;
  
  </code></pre>
  <pre><code>private void getQuestion() {
          String url = getString(R.string.api_server)+&quot;/question&quot;;
          ArrayList&lt;String&gt; initQuestion = new ArrayList&lt;&gt;();
  
          new Thread(new Runnable() {
              @Override
              public void run() {
                  Http http = new Http(User.this, url);
                  http.setToken(true);
                  http.send();
  
                  runOnUiThread(new Runnable() {
                      @Override
                      public void run() {
                          Integer code = http.getStatusCode();
  
                          if(code == 200){
                              try {
                                  JSONArray response = new JSONArray(http.getResponse());
  
  
                                  int length = response.length();
                                  if(length &gt; 0 ){
                                      for(int i=0; i &lt; response.length(); i++) {
                                          JSONObject object = response.getJSONObject(i);
                                          String question = object.getString(&quot;question&quot;);
                                          String lol = question.toUpperCase();
                                          initQuestion.add(lol);
  //                                        System.out.println(initQuestion);
  
                                      }
                                      System.out.println(initQuestion);
                                      finalQuestion(initQuestion);
                                  }else{
                                      tvQuestion1.setText(&quot;No Evaluation Available.&quot;);
                                  }
  
                              }catch (JSONException e){
                                  e.printStackTrace();
                              }
  
                          }
                      }
                  });
              }
          }).start();
  
      }
  
      private void finalQuestion(ArrayList&lt;String&gt; initQuestion) {
  
          StringBuilder question = new StringBuilder();
          for (int counter = 0; counter &lt; initQuestion.size(); counter++) {
              question.append(initQuestion.get(counter)+&quot;\n&quot;);
  
          }
          tvQuestion1.setText(question);
      }
  </code></pre>