title: Android - Gridview, custom layout onclicklistener
body: <p>I have a GridView with two TextViews inside it, When the GridView is populated, an OnClickListener is set which returns the position of the item that was selected. I want to trigger a method when one of the TextViews is selected. </p>
  
  <p>Is this possible? If yes, how do I set this up?</p>
  
  <p><strong>EDIT 3</strong>:</p>
  
  <p>Inside my activity whch populated the GridView: I retrieve a <code>String-Array</code> from my <code>Strings.xml</code>, a <code>for loop</code> examines each item inside the Array and searches for a condition based on the Item's name inside the SharedPreferences, this <code>for loop</code> is solely for counting how many "true" conditions there are, so it retrieves a <code>int</code> saved inside the <code>count</code>. Then a new <code>String[]</code> is created, this required an exact length to be given before items can be added to it, so I check <code>count</code> if it's more than 0, it will give the <code>String[]</code> a length of <code>count</code> and then another <code>for loop</code> will add each <code>true</code> to the <code>String[]</code> list that we just created. If <code>count</code> is 0 (no true conditions found in the first <code>for loop</code>) then only 1 Item is added to the <code>String[]</code> and is given the value "No Favourites Added".</p>
  
  <p>Then you have the GridView's OnItemClickListener().</p>
  
  <pre><code>        String s[] = getResources().getStringArray(R.array.FullList);
          int count = 0;
          for(int i = 0; i &lt; s.length; i++) {
              SharedPreferences sP = getActivity().getSharedPreferences("fav", MODE_PRIVATE);
              Boolean b = sP.getBoolean(s[i], false);
              if (b == true) {
                  count++;
              }
          }
          String[] newList;
          if (count &gt; 0) {
              newList = new String[count];
              count = 0;
              for(int i = 0; i &lt; s.length; i++) {
                  SharedPreferences sP = getActivity().getSharedPreferences("fav", MODE_PRIVATE);
                  Boolean b = sP.getBoolean(s[i], false);
                  if (b == true) {
                      newList[count] = s[i];
                      count++;
                  }
              }
          } else {
              newList = new String[1];
              newList[0] = "No favourites added";
          }
  
          GridView FavGV = (GridView) getActivity().findViewById(R.id.sexp_fav);
          FavGV.setAdapter(new Tab01_FavAdapter(getActivity(), newList));
          FavGV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView arg0, 
                      View arg1, int position, long arg3) {
  
                  //Intent i = new Intent(getActivity(), PosPreview_Gestures.class);
                  //i.putExtra("position", position);
                  //startActivity(i);
              }
          });
  </code></pre>
  
  <p>So that's the code inside the Activity which populates the GridView. The Adapter in it's original, functioning form: This simply populates the GridView with Favourite Items (their names from the String[]) and adds a TextView with "Remove" which when pressed, shows a Toast: "Remove". </p>
  
  <pre><code>public class Tab01_FavAdapter extends BaseAdapter {
  
      private Context mContext;
      private LayoutInflater mInflator;
  
      String mEntries[];     
      public Tab01_FavAdapter (Context c, String[] entries) {
          mContext = c;
          mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          mEntries = entries; 
      }
  
      @Override
      public int getCount() {
          return mEntries.length;
      }
  
      @Override
      public Object getItem(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          if(convertView == null) {
              convertView = mInflator.inflate(R.layout.favitemlayout, parent, false);
          }
  
          TextView tx = (TextView) convertView.findViewById(R.id.favgridremoveitem);
          OnClickListener oCL = new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(mContext,"Remove",Toast.LENGTH_SHORT).show();
              }
          };
          tx.setOnClickListener(oCL);
  
          return convertView;
      }
  }
  </code></pre>