title: How to pass 'this' to class for creating dynamically Views?
body: <p>in my Project,i have a class for creating dynamically Views like TextViews but i want click in views via <code>setonCLickListner</code> but this parameters is nat valid(this,Activity and Activity.getApplicationContext )</p>
  
  <p>My Code :</p>
  
  <pre><code>public a(Activity context , List&lt;Arr&gt; myarraylist){
  
         for (Array w : myarraylist) {
  
                      TextView textView = new TextView(context);
  
                      textView.setText(w.getW_text());
                      textView.setId(w.getW_id());
                      textView.setTag(w.getW_id());
                      textView.setTextColor(Color.parseColor("#000000"));
  
  
                      textView.setOnClickListener((View.OnClickListener) context.getApplicationContext());
  
                      //  textView.setOnClickListener(btnClickListener);
                      linearLayout.addView(textView);
                  }
  }
  </code></pre>
  
  <p>I got error:
  java.lang.ClassCastException: android.app.Application cannot be cast to android.view.View$OnClickListener</p>
  
  <p>and my problem is how to pass this object to java class and after click in anyview ,return value to activity in onClickListner</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  </code></pre>
  
  <p>and</p>
  
  <pre><code>   @Override
      public void onClick(View v) {
  
  
  
          LinearLayout ll = (LinearLayout) v.getParent();
          TextView tv = (TextView) ll.getChildAt(2);
  
          tv.setTextColor(Color.parseColor("#00ddff"));
  
  
  
      }
  </code></pre>