title: gridView injection with api photos and onItem click listener
body: <p><img src="https://i.stack.imgur.com/w2pkd.png" alt="That is actually what I want. All titles, gridviews and textViews are created dynamically."></p>
  
  <p>I'm using view injection like this. GridViews are created according to API data. </p>
  
  <pre><code>       if(followup.size()&gt;0)
      {
  
          for (Followup fData : followup) 
          {  
              String followupId= fData.get("id");
              LinearLayout lLayout=(LinearLayout) findViewById(R.id.lLayout); 
              LinearLayout ll1= new LinearLayout(this);
              ll1.setOrientation(LinearLayout.VERTICAL);
              TextView txtfup= new TextView(this);                
              txtfup.setBackground(getResources().getDrawable(R.drawable.bg));
              txtfup.setTypeface(face);
              txtfup.setText("    Followup " + i++);              
              txtfup.setTextColor(Color.WHITE);
              txtfup.setGravity(Gravity.LEFT);
              txtfup.setTextSize(18);
              LayoutParams params = new LayoutParams(
                      LayoutParams.FILL_PARENT,      
                      LayoutParams.WRAP_CONTENT
              );
              txtfup.setLayoutParams(params);             
              ll1.addView(txtfup);
  
              TextView txtEmpty= new TextView(this);
              txtEmpty.setText("");
              ll1.addView(txtEmpty);
              lLayout.addView(ll1);
  
              RelativeLayout rLayout=new RelativeLayout(this);
              LinearLayout.LayoutParams relativeParams = new LinearLayout.LayoutParams(
                      new LinearLayout.LayoutParams(
                              LinearLayout.LayoutParams.MATCH_PARENT,
                              LinearLayout.LayoutParams.WRAP_CONTENT));
              relativeParams.setMargins(40, 8, 40, 30);// left, top, right, bottom
              rLayout.setLayoutParams(relativeParams);
              rLayout.requestLayout();
  
              gridViewF= new GridView(this);
              gridViewF.setHorizontalSpacing(10);
              gridViewF.setNumColumns(5); 
  
  
  
              rLayout.addView(gridViewF);
              lLayout.addView(rLayout);
              //gridViewF.setOnItemClickListener(gridViewOnclickListener_followup);
              //---------------------------------
  
              RelativeLayout rLayout1=new RelativeLayout(this);
              LinearLayout.LayoutParams relativeParams1 = new LinearLayout.LayoutParams(
                      new LinearLayout.LayoutParams(
                              LinearLayout.LayoutParams.MATCH_PARENT,
                              LinearLayout.LayoutParams.WRAP_CONTENT));
              relativeParams1.setMargins(40, 10, 40, 40);// left, top, right, bottom
              rLayout1.setLayoutParams(relativeParams);
              rLayout1.requestLayout();
  
              TableRow row=new TableRow(this.getApplicationContext());
              TableRow row1=new TableRow(this.getApplicationContext());
  
              TableLayout tlayout=new TableLayout(this.getApplicationContext());
  
              row=new TableRow(this);
              row1=new TableRow(this);
  
              TableLayout.LayoutParams tableRowParams=
                        new TableLayout.LayoutParams
                        (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
  
                      tableRowParams.setMargins(6, 2, 6, 2);
  
                      row.setLayoutParams(tableRowParams);
                      row1.setLayoutParams(tableRowParams);
  
              TextView text1=new TextView(this);
              TextView text2=new TextView(this);
              TextView text3=new TextView(this);
              TextView text4=new TextView(this);
  
              text1.setTypeface(face); 
              text2.setTypeface(face1);
              text3.setTypeface(face);
              text4.setTypeface(face1);
              text1.setTextSize(18);
              text2.setTextSize(16);
              text3.setTextSize(18);
              text4.setTextSize(16);
              text1.setHeight(70);
              text2.setHeight(70);
              text3.setHeight(70);
              text4.setHeight(70);
  
              text1.setText("Description :  ");
              row.addView(text1);
              text2.setText(fData.get("note"));
              row.addView(text2);
              text3.setText("Followup Date :  ");
              row1.addView(text3);
              text4.setText(fData.get("followup_date"));
              row1.addView(text4);
              tlayout.addView(row);
              tlayout.addView(row1);
              rLayout1.addView(tlayout);
              lLayout.addView(rLayout1);
              //-----------------------------
  
              photo= new ArrayList&lt;Followup_Photos&gt;();
              for (Followup_Photos photos : followupPhoto) {
                  if(followupId.equalsIgnoreCase(photos.get("photo_type_id")))
  
                      photo.add(new Followup_Photos(photos.get("photo_id"), photos.get("photo_name"), photos.get("date_added"),
                              photos.get("photo_type_id")));
              }
              setGridView_Followup(photo);
              Log.i(TAG, "followup photos"+ followupPhoto.toString());
              Log.i(TAG, "photo array=&gt;"+ photo.toString());
              //------------------------------
              LinearLayout ll4= new LinearLayout(this);
              ll4.setOrientation(LinearLayout.HORIZONTAL);
              TextView txtView= new TextView(this);
              txtView.setLayoutParams(new LinearLayout.LayoutParams(
                      LinearLayout.LayoutParams.WRAP_CONTENT,
                      LinearLayout.LayoutParams.WRAP_CONTENT));
              txtView.setHeight(30);
              ll4.addView(txtView);
  
          }
  </code></pre>
  
  <p>But there is a problem when I call gridViewF.setOnItemClickListener. Because more than one gridViews are created inside the loop but are the same name gridViewF. So, may I know any suggestion, please?</p>