title: How to generate a TextView inside a thread inside a for loop in the main activity
body: <p>Is it possible to generate a TextView inside a for loop in the main activity? I have to run a thread from another Java class "multithread." When this class runs, I will know how many clients connected to, I will run the insider thread to generate TextViews according to the number of the clients, and display the received messages in these TextViews. </p>
  
  <p>But I am obtaining an error. If you know any better way to run a thread inside the main activity, please let me know, thanks.</p>
  
  <p>Here is the method:</p>
  
  <pre><code>public void toggleButtonConnectToClientsFunction(View view) {
  Thread t = new Thread(new Runnable() {
                  @Override
                  public void run() {
                      //Multithread here
                      multicastthreadRun.run();
                      for(int counter=0;counter&lt;multicastthreadRun.ClientIpArrayList.size();counter++) {
  
                          TextView textView=new TextView(this);//i am obtaining error here
                          linearLayoutSecondaryTexts.addView(textView);
  
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              //in this case we can change the user interface
  
  
  
                          }
                      });
                      }//end of the for loop
                  }
              });t.start();
  </code></pre>